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>

  • 相关阅读:
    使用迭代器模式批量获得数据(C#实现)
    如何从技术上预防抢票软件刷屏
    如何用Tesseract做日文OCR(c#实现)
    我的.net开发百宝箱
    程序员必备基础:Git 命令全方位学习
    Java 异常处理的十个建议
    50道Java集合经典面试题(收藏版)
    记一次接口性能优化实践总结:优化接口性能的八个建议
    100道MySQL数据库经典面试题解析(收藏版)
    800+Java后端经典面试题,希望你找到自己理想的Offer呀~
  • 原文地址:https://www.cnblogs.com/yuanws/p/1341299.html
Copyright © 2011-2022 走看看