本节讲一些基础性的东西
<%: Html.ActionLink( "修改", "Edit", new { Controller= "Movie",Action= "Edit",id=item.ID})%>
                                |
                                <%: Html.ActionLink( "明细", "Details", new { Controller = "Movie", Action = "Details", id = item.ID })%>
                                |
                                <%: Html.ActionLink( "删除", "Delete", new { id=item.ID })%>
第一二行跨controller,传送数据。第三行不跨,就在当前的控制器找action。
<%@ Page Title= "" Language="C# " MasterPageFile="~/Views/Shared/Site.Master " Inherits="System.Web.Mvc.ViewPage>" %>

"Content1" ContentPlaceHolderID= "TitleContent" runat= "server">
        Search

"Content3" ContentPlaceHolderID= "HeadContent" runat= "server">
        

"Content2" ContentPlaceHolderID= "MainContent" runat= "server">
        


                Search


        <% using (Html.BeginForm( "Edit", "Movie", FormMethod.Get))
             { %>
        
                
                        
                
                
                        
                        
                        
                        
                
                <% foreach (var item in Model)
                     { %>
                
                        
                        
                        
                        
                
                <% } %>
        
"4" style= "text-align: right">
                                "submit" value= "修改" onclick= "return isCheck();" />
                        

                                选择
                        

                                ID
                        

                                Movie_Name
                        

                                Realease_Date
                        

                                <%: Html.RadioButton( "Id", item.ID, new { onclick= "setValue(this);"})%>
                        

                                <%: item.ID%>
                        

                                <%: item.Movie_Name%>
                        

                                <%: String.Format( "{0:g}", item.Realease_Date)%>
                        

        


                <%: Html.Hidden( "hfdId") %>
        


        


                <%: Html.ActionLink( "返回", "Search", "Test")%>
        


        <%} %>

这个界面实现根据选中的行,修改值。
asp.net MVC2 初探五_第1张图片
修改页面为 using (Html.BeginForm("Edit", "Movie", FormMethod.Get))所指定的action对应的页面
asp.net MVC2 初探五_第2张图片
下面是一个datePick的例子
<%@ Page Title= "" Language="C# " MasterPageFile="~/Views/Shared/Site.Master " Inherits="System.Web.Mvc.ViewPage>" %>

"Content1" ContentPlaceHolderID= "TitleContent" runat= "server">

"Content3" ContentPlaceHolderID= "HeadContent" runat= "server">
        "../../Scripts/DataPicker/css/ui.all.css" />
        
        
        
        
        
        

"Content2" ContentPlaceHolderID= "MainContent" runat= "server">
        


                ShowDB


        <% using (Html.BeginForm( "Search", "Test"))
             {%>
        "table1">
                
                        
                        
                
                
                        
                        
                        
                        
                
                <% foreach (var item in Model)
                     { %>
                "SetNewColor(this);" onmouseout= "SetOldColor(this);" style= "cursor: hand">
                        
                        
                        
                        
                
                <% } %>
        
"2">
                                按时间从
                        
"2">
                                "text" id= "startTime" name= "startTime" />  至 "text"
                                        id= "endTime" name= "endTime" />
                                "submit" id= "btnSearch" value= "查询" />
                        

                        

                                ID
                        

                                MoviewName
                        

                                RealeaseDate
                        

                                <%: item.ID%>
                        

                                <%: item.Movie_Name%>
                        

                                <%: item.Realease_Date%>
                        
"width: 100%">
                                <%: Html.ActionLink( "Edit", "Edit", new { id = item.ID })%>
                                |
                                <%: Html.ActionLink( "Details", "Details", new { id = item.ID })%>
                                |
                                <%: Html.ActionLink( "Delete", "Delete", new { id = item.ID })%>
                        

        


                <%: Html.ActionLink( "Create New", "Create")%>
        


        

        

        <%} %>

效果如下,using (Html.BeginForm("Search", "Test", FormMethod.Get, new { autocomplete="off"}))这句用来限制自动完成
asp.net MVC2 初探五_第3张图片
点击文本框,弹出如下
asp.net MVC2 初探五_第4张图片
控制器代码
public ActionResult Search()
                {
                        ViewData.Model = m1.Movies.ToList();
                         return View();
                }
                [HttpPost]
                 public ActionResult Search(FormCollection fc)
                {
                        DateTime startTime = DateTime.Parse(fc[ "startTime"].ToString());
                        DateTime endTime = DateTime.Parse(Request.Form[ "endTime"].ToString()
                                );
                    
                        var Result = from m in m1.Movies where m.Realease_Date >= startTime && m.Realease_Date <= endTime select m;
                         return View(Result);
                }