Asp.net mvc 3 MVC3中未在部分视图中填充数据?
大家好,我有一个名为Grids的视图页面和名为History的部分视图,我想在我的网格页面中显示部分视图,我的页面中有视图,但历史页面中没有填充数据Asp.net mvc 3 MVC3中未在部分视图中填充数据?,asp.net-mvc-3,partial-views,Asp.net Mvc 3,Partial Views,大家好,我有一个名为Grids的视图页面和名为History的部分视图,我想在我的网格页面中显示部分视图,我的页面中有视图,但历史页面中没有填充数据 this is my GridsPage <% var grid = new WebGrid(source: Model, defaultSort: "ResourceName", rowsPerPage: 3); using (
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") %>
它不会进入操作方法历史记录..有人能纠正我在这里哪里做错了吗Html.Partial不会调用控制器。您需要在调用中指定模型:
<%: Html.Partial("History", GetBugs()) %>
另一个选项是RenderAction,它将调用控制器,实际上是整个运行时路由,等等:
<%: Html.RenderAction("History", "ControllerName"); %>
在控制器中
[ChildActionOnly]
public ActionResult History()
{
var getbugs = GetBugs();
return PartialView(getbugs);
}
在您的aspx页面中尝试以下更改
<%:Html.Action("History") %>
尝试在您的代码中进行此更改@simmon Whitehead对于您的第一个解决方案,我在GetBugs中发现一个错误。它不存在于contextGetBugs中。GetBugs必须是静态方法,并通过视图中的完整类型名进行调用,例如:YourProject.YourNamespace.YourClass.GetBugs。否则,请改用渲染。@Simon。。。我用第二种方法。。。我出错了expected@Simon..am使用的第二种方法。。。我收到错误…与“System.Web.HttpUtility.HtmlEncodestring”匹配的最佳重载方法有一些无效错误
[ChildActionOnly]
public ActionResult History()
{
var getbugs = GetBugs();
return PartialView(getbugs);
}
<%:Html.Action("History") %>