本文介绍了MVC 3不能通过字符串作为视图的模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的模型一个奇怪的问题传递给视图
I have a strange problem with my model passed to the View
控制器
[Authorize]
public ActionResult Sth()
{
return View("~/Views/Sth/Sth.cshtml", "abc");
}
查看
@model string
@{
ViewBag.Title = "lorem";
Layout = "~/Views/Shared/Default.cshtml";
}
错误消息
The view '~/Views/Sth/Sth.cshtml' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Sth/Sth.cshtml
~/Views/Sth/abc.master //string model is threated as a possible Layout's name ?
~/Views/Shared/abc.master
~/Views/Sth/abc.cshtml
~/Views/Sth/abc.vbhtml
~/Views/Shared/abc.cshtml
~/Views/Shared/abc.vbhtml
我为什么不能传递简单的字符串作为一个模式?
Why can't I pass a simple string as a model ?
推荐答案
是的,你可以,如果你使用的是正确的:
Yes you can if you are using the right overload:
return View("~/Views/Sth/Sth.cshtml" /* view name*/,
null /* master name */,
"abc" /* model */);
这篇关于MVC 3不能通过字符串作为视图的模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!