许多人都知道MVC4有一些很棒的新功能,我正在努力为ContextDependentView添加一个重载。我得到一个错误说没有ContextDependentView的重载方法接受1个参数。我正在使用的原始代码是
// This worked fine
return View(new ModelSample { getInfo= info, Retrieving= Retrieve })
// This is now what I have tried to do that doesn't work
return ContextDependentView(new ModelSample { getInfo= info, Retrieving= Retrieve })
//This is the method for ContextDependentView()
private ActionResult ContextDependentView()
{
string actionName = ControllerContext.RouteData.GetRequiredString("action");
if (Request.QueryString["content"] != null)
{
ViewBag.FormAction = "Json" + actionName;
return PartialView();
}
else
{
ViewBag.FormAction = actionName;
return View();
}
}
我明显看到没有重载但是如何在ContextDependentView方法中添加一个重载来接受我的模型,如返回View() ..谢谢
答案 0 :(得分:0)
将此重载添加到控制器:
private ActionResult ContextDependentView(SampleModel model)
{
string actionName = ControllerContext.RouteData.GetRequiredString("action");
if (Request.QueryString["content"] != null)
{
ViewBag.FormAction = "Json" + actionName;
return PartialView();
}
else
{
ViewBag.FormAction = actionName;
return View();
}
}
这应该有用......