我在 mvc3 中创建了一个 Web 应用程序,并创建了两个部分视图,其中一个具有下拉列表等控件。第二个有 webgrid,它显示来自数据库的数据。
partialview1.cshtml
@model Mapping.Models.SecurityIdentifierMapping
@using (Html.BeginForm("Mapping", "Home"))
{
@Html.DropDownList("SecurityID", Model.PricingSecurityID, "-- Select SecurityID --")
<br />
@Html.DropDownList("CUSIPID", Model.PricingSecurityID, "-- Select CUSIPID --")
<br />
<button type="submit">Map</button>
}
partialview2.cshtml
@model IEnumerable<Mapping.Models.SecurityIdentifierMapping>
@{
ViewBag.Title = "Mapping";
WebGrid grid = null;
if (Model.Count() > 0 ){
grid = new WebGrid(source: Model,
defaultSort: "Id",
canPage: true,
canSort: true,
rowsPerPage:20);
}
}
<h2>Mapping</h2>
@if (grid != null)
{
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("", header: null, format: @<text>@Html.ActionLink("Edit", "Edit", new { id = (int)item.id }) @Html.ActionLink("Delete", "Delete", new { id = (int)item.id })</text>),
grid.Column("PricingSecurityID"),
grid.Column("CUSIP")
)
)
}
<br />
<p>
@Html.ActionLink("Back", "Index")
</p>
in index.cshtml
<div>
@Html.Partial("_ControlsPartial",)
</div>
<div>
@Html.Partial("_WebGridPartial")
</div>
HomeController.cs
public ActionResult Index()
{
SecurityIdentifierMapping objModel = new SecurityIdentifierMapping();
objModel.PricingSecurityID = objRepository.GetPricingSecurityID();
objModel.CUSIP = objRepository.GetCUSIP();
return View(objModel);
}
我如何显示 webgrid 并使用相同的 Index() 填充下拉列表?
出现错误:(@Html.Partial() 中的第二个参数应该是什么,以便网格和控件在同一页面上都可以正常工作。?