0

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 Control which controller and action to use?

This is in ASP.net MVC2

2 Answers 2

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.