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

后端 未结 7 1563
忘了有多久
忘了有多久 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:28

    This seems so pretty obvious but maybe someone needs more clarification in the future:

    If in your controller do:

      string id = "abc";
      return View(model: id);
    

    Then in your view, you need:

    @model string
    

    In order to get the value, for e.g.:

    <div>@Model</div>
    
    0 讨论(0)
提交回复
热议问题