开发者

Passing data from controller to MVC2 User Control

开发者 https://www.devze.com 2023-02-13 08:54 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消