MVC pass model object from controller to view

前端 未结 3 1576
北海茫月
北海茫月 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:09

    It's better to set it up where your view does not call your controller. Load all of the data for the request in the action which calls this view and populate a view model with the needed data. Once you have that, render the fields from the model.

    As for your actual problem. The action that calls this view in the first place populates the ViewData.Model for its context. When you call the action method, the framework is creating a new context with its own ViewData which you dont have access to without a handle to that newly created context.

提交回复
热议问题