[英]How to load correctly a partial view in mvc?
在我的mvc项目中,我有一个具有以下操作的控制器:
public ActionResult Index()
{
return View(new List<Product>());
}
相应的索引视图使用主网格呈现局部视图:
@model System.Collections.Generic.List<TbbModels.Domain.Product>
@Html.Partial("_ProdutoMasterGrid", Model)
此局部视图具有一个提交按钮和一个网格。 客户需要在表单中放入一些数据并将其提交给该操作:
public ActionResult _ProdutoMasterGrid(string param)
{
return PartialView("_ProdutoMasterGrid",
repository.Compare(param).ToList());
}
但是比起我没有布局的网格。 如何返回布局的局部视图?
您应该显式返回正确的视图:
public ActionResult _ProdutoMasterGrid(string param)
{
return View("Index",
repository.Compare(param).ToList());
}
这样可以确保在您对此操作进行发布时,它返回索引视图。 我在这里假设repository.Compare
返回一个List<Product>
,因为类型需要匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.