asp.net mvc - .NET URL with categories -


There are some problems managing URLs that look good for my site.

I have 3 models : city , restaurants , food .

TownController is using Town service and index shows all cities (other methods are Edit , create , delete ) using the Restaurants and Index and then / Code> shows restaurants

similarly with town )

FoodController - FoodService Using the index to show all foods code> is selected Restaurant

url:

/ city - all cities P>

< ID = 1 shows all with city in the code> / restaurant / index / 1 - restaurant < ID = 1 with / food / index / 1 - all foods in restaurants >

Only / town is the correct URL, the rest is not good, should be like second / town / 1 , but ever since the restaurant controller has all races National in city is visible, it / restaurants / index / 1.

Is there any way to change that construct? Also keep in mind that the customer insists on not using custom routes / specialty routing.

Finally, the best SEO / Town / TownName / RestaurantID will be (or even restaurantName ) but it is not important that if you last Can help me with the request.

Thank you.

You need to modify and add RouteConfig.cs to some custom routes in your App_Start folder. Your register register method

  routes. The default route should be the following in MapRoute (name: "default", url: "{controller} / {action} / {id}", default: new {controller = "home", action = "index", id = url parameter Optional}   

This passage means that if you do not give it anything for controller, verb or ID, if you pass it to a controller pass / city / index, The following routes register before the default route MapRoute (name: "restaurant", url: "Town / {id}", default: new {controller = "restaurant"}, then the default route should always be. , Action = "index", id = UrlParameter.Optional});

This will capture any URL containing '/ Town /' and an integer, while still '/ Town' Controller.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -