requirements, there are two different pages, and there is a div where the data is public! But the data of the div is not fixed, the data is changing! In fact, it is also a partial view.
Previously, when we used MVC to load local views, we did it as follows:
@{Html.RenderPartial("Test",ViewData["aaa"]); } @Html.Partial("Test") In the past, the local view, the total part of the data was generally fixed content or the viewdata of the current controller was passed in, and the above two methods actually did not enter the controller layer, so the efficiency was higher, but it did not meet my requirements!
My request is that the local view can enter the controller to load the data, dynamically generate the data and then return!
Similarities and differences between Partial and Action
Similarities:
It is usually used to display a relatively independent "block", such as a display menu or navigation bar. The results of both outputs are displayed as part of the called View
Differences:
The data for the RenderPartial comes from the calling View, and the RenderAction accesses the controller.
RenderAction initiates a new Request, while RenderPartial does not.
Html.RenderActionAllows you to call an Action directly, and display the returned result directly in the currently called View, with a method in Control and return the PartialView
First, create a new Test method in the Home controller, the code is as follows:
Test.cshtml code:
How do I call the local view?
|