I am trying to learn the new ASP.NET MVC framework and would like to know how best to use UserControls.
I understand that you can display UserControl as partial and transmit data from the controller. Ideally, I would think that it makes sense not to have code behind the file, as this creates the temptation to break MVC rules.
I will give an example where I do not understand how UserControls fit into the template.
I have a UserControl that shows the latest tags (as on Stack Overflow). Unlike StackOverflow, I want to display this UserControl on all of my pages. If I have a controller says QuestionController which is designed to handle actions from some questions, for example. view and detail, does this mean that I have to get the data in the QuestionController and then pass it to the UserControl?If I create another controller, tell SearchController then I will have to copy the same functions as get the latest tags in order to go to partially again. Doesn’t this mean that 2 different controllers are additional things that they were not originally intended for?
I have a UserControl that shows the latest tags (as on Stack Overflow). Unlike StackOverflow, I want to display this UserControl on all of my pages. If I have a controller says QuestionController which is designed to handle actions from some questions, for example. view and detail, does this mean that I have to get the data in the QuestionController and then pass it to the UserControl?
If I create another controller, tell SearchController then I will have to copy the same functions as get the latest tags in order to go to partially again. Doesn’t this mean that 2 different controllers are additional things that they were not originally intended for?
UserControl , , ViewData UserControl, OnActionExecuting . UserControl , , ActionFilterAttribute . , , UserControl.
, UserControl . , ( , , ) ( OnActionExecuting).
, ASP.NET MVC 2 RenderAction , . , , .
. ( ) , . .