I have a MVC2 user control that I want to dynamically load the menu from the controller.
I will use LINQ to SQL to get the data that I want to pass to the user control.
How can I tell the MVC2 User Cont开发者_运维知识库rol which controller and action to use?
This is in ASP.net MVC2
You can use the Html.RenderAction
helper:
<% Html.RenderAction("ActionName", "ControllerName"); %>
From your controller you should return a PartialViewResult
:
public ActionResult ActionName()
{
var menuItems = DB.GetMenuItems();
return PartialView("MenuViewName", menuItems);
}
Normally the controller tells which view to use and not vice versa.
But you can use the RenderAction Html helper to call a child action which returns the concrete partial view
精彩评论