相关疑难解决方法(0)

MVC 3无法将字符串作为View的模型传递?

传递给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 asp.net-mvc-routing asp.net-mvc-3

64
推荐指数
4
解决办法
3万
查看次数

当我的模型在我的ASP.NET MVC应用程序中为null时,EditorFor(..)抛出异常

我有一个非常简单的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(..)

asp.net asp.net-mvc razor

5
推荐指数
1
解决办法
1674
查看次数