Question

I'm reading Adam's book Pro ASP .NET MVC 4 and I have a question what does this code do?

@Html.RouteLink(link, new
    {
        controller = "Product",
        action = "List",
        category = link,
        page = 1
    },
    new {
        @class = link == ViewBag.SelectedCategory ? "selected" : null
    })

Additionally, I have a controller with the method inside

public PartialViewResult Menu(string category = null)
{
            ViewBag.SelectedCategory = category;
            IEnumerable<string> categories = repository.Products
              .Select(x => x.Category)
              .Distinct()
              .OrderBy(x => x);
            return PartialView(categories);
}

Thank you for your help!

Was it helpful?

Solution

Quote from MSDN:

RouteLink returns an anchor element (a element) that contains the virtual path of the specified action.

It means it will generate following html a tag

<a href="myserver/Product/List...">linkstring</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top