MVC 3 Can't pass string as a View's model?

后端 未结 7 1564
忘了有多久
忘了有多久 2021-02-03 16:46

I have a strange problem with my model passed to the View

Controller

[Authorize]
public ActionResult Sth()
{
    return View(\"~/Views/S         


        
7条回答
  •  深忆病人
    2021-02-03 17:15

    You meant this View overload:

    protected internal ViewResult View(string viewName, Object model)
    

    MVC is confused by this overload:

    protected internal ViewResult View(string viewName, string masterName)
    

    Use this overload:

    protected internal virtual ViewResult View(string viewName, string masterName,
                                               Object model)
    

    This way:

    return View("~/Views/Sth/Sth.cshtml", null , "abc");
    

    By the way, you could just use this:

    return View("Sth", null, "abc");
    

    Overload resolution on MSDN

提交回复
热议问题