【发布时间】:2016-02-24 17:25:53
【问题描述】:
我有这个控制器:
public ActionResult PopulateTreeViewModel()
{
MainModelPopulate mainModelPopulate = new MainModelPopulate();
// populate model
return View(mainModelPopulate);
}
有这样的观点:
@model xxx.xxx.MainModelPopulate
<table>
@foreach (var item2 in Model.CountryList)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item2.CountryName);
</td>
</tr>
foreach (var item3 in item2.BrandList)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item3.BrandName);
</td>
</tr>
foreach (var item4 in item3.ProductList)
{
<tr>
<td>
@Html.ActionLink(item4.ProductName, "FunctionX", new { idLab = item3.BrandID, idDep = item4.ProductID });
</td>
</tr>
}
}
}
</table>
FunctionX 控制器是这样的:
public ActionResult FunctionX(int idBrand=1 , int idProd=1)
{
List<ListTypeModel> typeModelList = new List<ListTypeModel>();
// populate typeModelList
return PartialView(typeModelList);
}
}
用这个局部视图:
@model IEnumerable<TControl.Models.ListTypeModel>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
</tr>
}
</table>
我想在我的主视图 (PopulateTreeViewModel) 中添加这个局部视图,并使用函数 X 中包含的相关产品类型更新表格。
我也尝试用@Ajax.ActionLink 替换@Html.ActionLink,它的执行方式相同。
【问题讨论】:
标签: asp.net-mvc-4 renderpartial html.actionlink