我正在尝试从Grid.MVC传递参数
这是我的代码:
Details.cshtml
@Html.Grid(Model).Columns(columns =>
{
columns.Add(c => c.CustomerID).Titled("Customer ID").Filterable(true);
columns.Add(c => c.CustomerName).Titled("Customer Name").Filterable(true);
columns.Add()
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(o => Html.ActionLink("Edit", "Edit", new { id = o.CustomerID }));
}).WithPaging(10).Sortable(true)
当我点击网格视图的编辑部分时,我试图将o.CustomerID
传递给公共ActionResult HomeController
{int Edit
<{p >
ModelCustomID
这里是Edit.cshtml
MVC.Grid.Models.Sales_DWEntities salesin = new Models.Sales_DWEntities();
List<Models.DimCustomer> CustomerList = new List<Models.DimCustomer>();
public ActionResult Details()
{
CustomerList = (from sales in salesin.DimCustomers select sales).ToList();
return View(CustomerList);
}
public ActionResult Edit(int ModelCustomID)
{
var custid = (from sale in salesin.DimCustomers where sale.CustomerID == ModelCustomID select sale).FirstOrDefault();
return View();
}
作为@model MVC.Grid.Models.DimCustomer
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>DimCustomer</legend>
<div class="editor-label">
@Html.LabelFor(model => model.CustomerID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CustomerID)
@Html.ValidationMessageFor(model => model.CustomerID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CustomerAltID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CustomerAltID)
@Html.ValidationMessageFor(model => model.CustomerAltID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CustomerName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CustomerName)
@Html.ValidationMessageFor(model => model.CustomerName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Gender)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Gender)
@Html.ValidationMessageFor(model => model.Gender)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
视图中的结果:
除了Edit.cshtml
我的问题是:
发件人:
null
然后传递o.CustomerID值
:.RenderValueAs(o => Html.ActionLink("Edit", "Edit", new { id = o.CustomerID }));
控制Edit(int ModelCustomID)
Edit.cshtml
这是我的RouteConfig.cs
public ActionResult Edit(int ModelCustomID)
{
var custid = (from sale in salesin.DimCustomers where
sale.CustomerID == ModelCustomID select sale).FirstOrDefault();
return View();
}
非常感谢任何想法。