MVC3中的部分视图中未填充数据?

时间:2012-07-31 11:51:44

标签: asp.net-mvc-3 partial-views

大家好我有一个视图页面命名网格和部分视图命名历史记录,我想在我的网格页面中显示局部视图,我在我的页面中有视图但历史记录页面没有填充其中的数据

   this is my GridsPage

      <%       
                   var grid = new WebGrid(source: Model, defaultSort: "ResourceName", rowsPerPage: 3);
                     using (Html.BeginForm())
                     { %>  

                         <%: Html.DropDownList("ResourceName", (SelectList)ViewBag.ResourceName, "--Select Project--")%>
                          <%: Html.ValidationMessage("ResourceName")%>  

                           <%: Html.DropDownList("ResourceID", (SelectList)ViewBag.ResourceID, "--Select Project--")%>
                           <%: Html.ValidationMessage("ResourceID")%> 

                           <%: Html.DropDownList("status", (SelectList)ViewBag.status, "--Select Project--")%>                               
                                <form action="Grids.aspx" method="post">
                                <p>
                                 <input type="submit" value="search" />
                               </p> 
                               </form>                          
                        <div id="grid">
                        <%:grid.GetHtml(
                         tableStyle: "listing-border", headerStyle: "gridhead", footerStyle: "paging", rowStyle: "td-dark", alternatingRowStyle: "td-light",                            
                         columns:grid.Columns(                             
                        grid.Column("ResourceID","Resource ID"),
                        grid.Column("ResourceName","Resource Name"),
                        grid.Column("EmployeEmailID","Employee ID"),
                        grid.Column("status","Status"),
                        grid.Column(
                        header: "",
                        style: "text-align-center",
                        format: (item) => Html.ActionLink("Edit", "Edit", new { ResourceID = item.ResourceID }))
                        ))%>
                        </div>
                        <%} %>

               //Rendering the Partial view here
                        <%:Html.Partial("History") %>

这是我的部分视图

       <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Gridview_BugTracker.Models.BugTracker_DataHelper>>" %>                 
               <% foreach (var item in Model)
                  { %>                        
                     <div>
                      <%:Html.LabelForModel(item.EmployeName)%>
                     </div>                        
                     <div>
                     <%:Html.LabelForModel(item.Resolution)%>
                     </div>

这是我的部分视图控制器

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult History()
    {
        var getbugs = GetBugs();
        return View(getbugs);
    }

它没有进入行动方法的历史......任何人都可以纠正我在哪里做错了

2 个答案:

答案 0 :(得分:0)

Html.Partial不会调用控制器。您需要在调用中指定模型:

<%: Html.Partial("History", GetBugs()) %>

另一个选项是RenderAction,它将调用控制器,实际上是整个运行时(路由等):

<%: Html.RenderAction("History", "ControllerName"); %>

答案 1 :(得分:0)

在您的控制器中

[ChildActionOnly]
public ActionResult History()
{
    var getbugs = GetBugs();        
    return PartialView(getbugs);
}

并在您的aspx页面中尝试此更改

       <%:Html.Action("History") %>

在您的代码中尝试此更改