I'm trying to add a navigational menu for my project which uses the ASP.NET framework and C# programming language. My solution is to create a widget which can populate a partial view when called from the master page. In the widget's action method, how do I add Links or Controller-Action combinations to the ViewDataDictionary?
--- Edit : Here is my code, after your suggestion
public class NavController : Controller
{
public ActionResult Menu()
{
List<ActionLink> navLinks = new List<ActionLink>();
navLinks.Add(new ActionLink() { Text = "Home", ActionName = "Index", ControllerName = "Home" });
return View(navLinks);
}
}
The partial view file looks like the following:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<Microsoft.Web.Mvc.Controls.ActionLink>>" %>
<% foreach(var link in Model) { %>
<%= link %>
<%} %>
But the output of all this is simply 'Microsoft.Web.Mvc.Controls.ActionLink' and not the link which I want.
Thanks.