I have urls that look like this
~\articles\energy\topweek
~\articles\metals\latestpopular
where second url string is a category and third is a filter
so route looks like this
routes.MapRoute("ArticleFilter",
"articles/{category}/{filter}",
new { controller="Article", action="Filter" })
That’s pretty easy and everything works fine.
So lets say if i’m looking at articles{category}\ default view.
How do I construct links to point to current category with filters.
Example:
If current page articles\energy, I need to construct article\energy\topweek and article\energy\latestpopular.
Where category should be dynamic based on the current page.
preferably in a partial view so I can use it across different pages.
Create an object for your usercontrol to take as model like this :
And your user control :
<%@ Control Language="C#"Inherits="System.Web.Mvc.ViewUserControl<Namespace.ArticleLinksControl>" %>
Assuming your view for the ArticleController’s default action also accepts a model that holds the information about the category name, you can send the category name to your user control this way :
Now in your usercontrol you can access the category name with
Model.CategoryName.This is if you insist on using a usercontrol for this. You can also get away with using Html helpers on your view.