zoukankan      html  css  js  c++  java
  • asp.net mvc beta使用心得

    1。        Controllers/HomeController.cs

         //基本数据获取

            public ActionResult Index()
            {
                ViewData["Title"] = "Home Page";
                ViewData["Message"] = "Welcome to ASP.NET MVC!";
                ViewData["users"] = Models.home.GetUserList();   //获取多条记录
                ViewData["city"] = Models.home.GetcityList();    //获取多条记录
                ViewData["link"] = Models.home.GetcityList()[0]; //获取单条记录

               return View()

             }

         //ajax请求的操作

            [AcceptVerbs(HttpVerbs.Post)]
            public ActionResult Add()
            {
                string cityname = Request.Form["username"];
                Models.home.IndertCity(cityname);

                return RedirectToAction("index");
            }

    2。Views/Home/Index.aspx

     

    <asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <script src="/mvc/Scripts/jquery-1.2.6.js" type="text/javascript"></script>
        <h2><%= Html.Encode(ViewData["Message"]) %></h2>
        <!--链接-->
        <h2><%=Html.ActionLink("about","about","home") %></h2>
        <h2><%=Html.ActionLink("about2","about") %></h2>
        <h2><%=Html.ActionLink("about", "../home/about")%></h2>
       
        <form action="home/Add" method="post" id="commentform">

        <h2><%=Html.TextBox("username","aa") %></h2>
        <h3>
            <input id="Submit1" type="submit" value="提交" /></h3>
            <h4><%=ViewData["strings"]%></h4>   
        </form>
       
       
        <p>
            To learn more about ASP.NET MVC visit <a href="
    http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
        </p><p>
        <% List<MvcApplication1.jz_user> users = ViewData["users"] as List<MvcApplication1.jz_user>;
            foreach(MvcApplication1.jz_user aa in users )
            {
            %><%= aa.name %>
           
          <% }%> </p>
         <p id="cityss">
        <% List<MvcApplication1.jz_city> citys = ViewData["city"] as List<MvcApplication1.jz_city>;
           foreach (MvcApplication1.jz_city aa in citys)
            {
            %><%=aa.name %>
           
          <% }%> </p> 
          <p>
          <%MvcApplication1.jz_city bb = ViewData["link"] as MvcApplication1.jz_city;%>
          <%=bb.name %>
          </p>
    <script type="text/javascript" language="javascript">   
    //我们只需要在这里注册一下事件就可以

        $(document).ready(function() {

     

            $("#commentform").ajaxForm(success);
            function success(data) {

                if (data != "") { document.getElementById("cityss").innerHTML += document.getElementById("username").value; document.getElementById("username").value = ""; }
            }

        });

    </script>  
    </asp:Content>

  • 相关阅读:
    Centos7.6安装教程 && history设置显示执行命令的时间
    C# 调用第三方webapi 接口的示例(使用httpclient)
    asp.net core 上传文件
    Sql中CHARINDEX用法---判断数据库某个字段是否包含某个字符
    ASP.NET上传文件出现“404-找不到文件或目录”的解决办法
    C# 中转换的几种方式
    C# 向文件写入和读取文件内容
    C# 中正则表达式
    C# 写的通用得到富文本框中的图片路径
    C# 正则表达式输入验证必须为汉字
  • 原文地址:https://www.cnblogs.com/yuanws/p/1341299.html
Copyright © 2011-2022 走看看