This article is a mirror article of machine translation, please click here to jump to the original article.

View: 22058|Reply: 1

[ASP.NET] asp.net mvc uses the RenderAction local view to load dynamic data

[Copy link]
Posted on 6/7/2018 5:07:32 PM | | | |
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?







Previous:Update your database with Code First migration
Next:The solution to the 360 search not including the inside pages of the website
 Landlord| Posted on 7/4/2019 9:24:08 PM |
@RenderBody、@RenderSection、@RenderPage、Html.RenderPartial、Html.RenderActi...
https://www.itsvse.com/thread-2172-1-1.html
(Source: Architect_Programmer)
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com