Diin
Diin

Reputation: 585

Custom MVC3 SEO friendly Url

I need help with custom url in MVC3. I have a news table and in the table I have categories like , Education, Business,Entertainment etc.

Now I want to get url pattern like mysite.com/entertainment/news/id/title-text. or mysite.com/news/entertainment/id/title-text

The controller will be the News. My initial thought was to create the sub controllers in news controller and create separate views for these sub controllers but I am wondering if that will be the best approach. I am also planning that if one types mysite.com/news/entertainment a filtered page of only the recent entertainment posts should display. Please guide or assist if possible.

Thanks

Upvotes: 0

Views: 663

Answers (1)

Diin
Diin

Reputation: 585

I have found out how to fix this to get a url like

mydomain.com/news/entertainment/Title-123

routes.MapRoute(
"NewsRoute", // Route name
"{controller}/{category}/{Title}-{id}",
 new{ controller = "News", action = "Details",id = UrlParameter.Optional}
);

Upvotes: 1

Related Questions