简体   繁体   中英

Can I return to the controller when loading a partial view? - asp.net MVC

I have a partial view that I want to basically "take care of itself" and not have to pass it a preloaded Model from my parent view other than a single ID.

My partial view would then take the ID and load the relevant data from a db using code in the controller and pass it back to its view to display it.

I think what you're looking for is RenderAction.

http://davidhayden.com/blog/dave/archive/2009/04/04/ASPNETMVCPartialViewsHtmlRenderActionASPNETMVCFutures.aspx

It's not built in as you'll need the futures.

Yes it's possible

Pass the id

<% Html.RenderPartial("MyPartial", ViewData.Model.Id); %>

Then you have to use ajax in your partial asking the controller for data see:

http://docs.jquery.com/Ajax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM