lar*_*ryq 1 actionresult asp.net-mvc-3
我有一个返回ActionResult的控制器.具体来说,它return View(someViewModel)在方法结束时调用.这是方法签名:
protected ActionResult SomeControllerMethod(AViewModel someViewModel)
Run Code Online (Sandbox Code Playgroud)
我随后继承自AViewModel(AnInheritedViewModel),为类添加了一些新属性,现在我将它传入SomeControllerMethod.
现在,在此方法结束时的return语句中,我收到有关如何找不到视图的错误.这很公平,但我不确定这一切都是默认的.
视图名称MVC告诉我它正在寻找不与控制器方法或模型类型的名称对齐.按照相同的模式,没有与原始模型的名称相对应的视图.所以我不确定MVC如何决定它将使用哪个视图?
当你
public ActionResult SomeControllerMethod()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
MVC尝试查找名为"SomeControllerMethod.cshtml"的视图.它使用方法的名称作为查找视图文件的指南.
您可以通过以下方式覆盖:
public ActionResult SomeControllerMethod()
{
return View("MyView");
}
Run Code Online (Sandbox Code Playgroud)
因此MVC将尝试找到"MyView.cshtml".
| 归档时间: |
|
| 查看次数: |
3655 次 |
| 最近记录: |