tags:

views:

51

answers:

1

I am used to ASP.NET where each user control would have its own codebehind, and you do things related to that usercontrol in that codebehind C#.net file, so you can reference the usercontrol anywhere you like.

I am new to ASP.NET MVC, and I added an ascx control, and I can not seem to figure out where do I write the code for setting viewdata specific to that control? I have this ascx control inside my master page, so the setting up for viewdata for that control should be at such a place that is available to all pages, so I can not do it inside Index() or something.

A: 

If you need a partial view (.ascx) that has its own controller ("code-behind") associated with it, consider using RenderAction() rather than RenderPartial().

http://blogs.intesoft.net/post/2009/02/renderaction-versus-renderpartial-aspnet-mvc.aspx

Robert Harvey
RenderAction() is supported in 2.0 version of MVC framework
kilonet
@kilonet: RenderAction is also in the MVC Futures assembly of version 1.0 (Microsoft.Web.Mvc)
Robert Harvey