MVC pass model object from controller to view

前端 未结 3 1609
北海茫月
北海茫月 2021-01-25 00:41

I am trying to figure out how to pass the model object from controller to view in a following scenario:

<% Html.Action(\"GetRequest\", \"The_Controller\", new         


        
3条回答
  •  自闭症患者
    2021-01-25 01:10

    You could have the controller action return the partial view:

    <%= Html.Action("GetRequest", "The_Controller", new { requestId = 12 }) %>
    

    And in your controller action:

    public ActionResult GetRequest(int requestId)
    {
        var request = _repository.GetRequest(requestId);
        return PartialView("Request", request);
    }
    

    This way the GetRequest action will pass the request object to the strongly typed Request.ascx partial view and include it in the page at the place you called Html.Action helper.

提交回复
热议问题