Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc child actions

I have worked with asp.net web forms a lot but this is my first ASP.Net MVC application. What I would like to do is use a child view to render some controls which are displayed and manipulated (relatively) independently of the page.

for example, say I have a calendar "gadget" that uses server side logic to display a list of events every time a date is clicked, completely independently of the processing on the rest of the page.

In web forms I could just create an ASCX (web user control). When a date is clicked in the control, the whole page is posted back but I can just put the click handling inside the calendar control; the rest of the page is round-tripped automatically without having to put in any specific logic to handle the calendar control's postback.

with MVC if I route the "date clicked" action to a calendar controller, this has no knowledge of the page it's embedded in so it can only draw the calendar, not the rest of the page. The only workaround I can think of (apart from ajax) is to have the owning page's controller handle all the calendar click actions and passing them onto the calendar controller before rendering the view for the whole page

Hopefully I've missed something obvious.

like image 862
Andy Avatar asked Nov 27 '22 20:11

Andy


1 Answers

Look at Partial Views and RenderAction.

Here are some URLS to get you started

http://rachelappel.com/razor/partial-views-in-asp-net-mvc-3-w-the-razor-view-engine/

http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx

http://devlicio.us/blogs/derik_whittaker/archive/2008/11/24/renderpartial-vs-renderaction.aspx

like image 185
Daveo Avatar answered Jan 03 '23 06:01

Daveo