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>

  • 相关阅读:
    gitlab 拉代码提示:Your Account has been blocked. fatal: Could not read from remote repository. 最佳解决方案
    关于C语言开大数组溢出的问题
    三元组转置稀疏矩阵
    传递二维数组
    vue3下把json放哪才能获得get到
    VM下Ubuntu的nat模式连不上wifi
    C3863 不可指定数组类型“int [510]”
    PAT1005 Spell It Right
    PAT1004 Counting Leaves
    PAT1002 A+B for Polynomials
  • 原文地址:https://www.cnblogs.com/yuanws/p/1341299.html
Copyright © 2011-2022 走看看