Reputation: 565
How do I produce this result? www.domain.com/brand/brand-name where brand = {controller} parameter = {brand-name}
routes.MapRoute(
name: "Brand Details",
url: "{controller}/{brandName}",
defaults: new { controller = "Brand", action = "Index", brandName = UrlParameter.Optional }
);
View: \Brand\Index.cshtml, which will be the default action result view.
I am getting a 404 error at this time.
Output expectation: http://www.domain.com/brand => will not be allowed http://www.domain.com/brand-name => will not be allowed http://www.domain.com/brand/brand-name => will get details of brand-name and return view.
Upvotes: 0
Views: 28
Reputation: 26
you should route like this
routes.MapRoute(
name: "Brand Details",
url: "Brand/{brandName}",
defaults: new { controller = "Brand",
action = "Index",
brandName = UrlParameter.Optional }
);
Upvotes: 1