asp.net-mvc - MVC 3 无法将字符串作为 View 模型传递?

标签 asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing

我的模型传递到 View 时遇到一个奇怪的问题

Controller

[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

为什么我不能传递一个简单的字符串作为模型?

最佳答案

是的,如果您使用正确的overload,则可以:

return View("~/Views/Sth/Sth.cshtml" /* view name*/, 
            null /* master name */,  
            "abc" /* model */);

关于asp.net-mvc - MVC 3 无法将字符串作为 View 模型传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9802546/

相关文章:

asp.net-mvc - HandleError 属性没有任何作用

c#文件路径中的非法字符

asp.net-mvc - 用于 MVC 3 的 Ioc 容器?

asp.net-mvc - 如何删除查询字符串中的空参数asp.net mvc

asp.net-mvc - Url.Action 在某些环境中返回空字符串

c# - asp.net core 中 GetUserManager 的替代

c# - ASP.NET Rotativa 从另一个 Controller 的 View 生成 PDF

asp.net-mvc-3 - Entity Framework :更新相关实体

asp.net-mvc-3 - MVC3 与 Npgsql 和 Entity Framework 和 .Net 框架 4

c# - RouteCollection”不包含“MapMvcAttributeRoutes”的定义