传递给View的模型有一个奇怪的问题
调节器
[Authorize]
public ActionResult Sth()
{
return View("~/Views/Sth/Sth.cshtml", "abc");
}
Run Code Online (Sandbox Code Playgroud)
视图
@model string
@{
ViewBag.Title = "lorem";
Layout = "~/Views/Shared/Default.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
错误消息
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
Run Code Online (Sandbox Code Playgroud)
为什么我不能将简单的字符串作为模型传递?
我有一个非常简单的ASP.NET MVC View,它有一个简单string的模型.
例如.
@model string
当我执行以下操作时,如果模型值为null(当用户首次登陆此视图/页面/资源时发生),视图将引发异常.
Value cannot be null or empty.
Parameter name: name
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Value cannot be null or empty.
Parameter name: name
<td>@Html.EditorFor(model => model)</td>
Run Code Online (Sandbox Code Playgroud)
当字符串模型值为null时,如何创建input box使用EditorFor(..)?