Can I generate ASP.NET MVC routes from a Sitemap?

I am going to study the structure ASP.NET MVCfor the upcoming project. Can I use advanced routing to create long URLs based on a hierarchy of site maps?

An example of a navigation path:

Home> Shop> Products> Home Appliances> Kitchen> Cookware> Cookers> Nonstick

Typical (I think) MVC URL:
http://example.com/products/category/NonstickCooksets

Desired URL:
http://example.com/shop/products/household/kitchen/cookware/cooksets/nonstick

Can I do it?

+3
source share
2 answers

, , . biggie, MVC Preview 3 ( , 3 4), .

,

"{}/{}/{* categoryPath}"

URL-, :

http://example.com/shop/products/household/kitchen/cookware/cooksets/nonstick

ShopController Products:

public class ShopController : Controller
{
...
    public ActionResult Products(string categoryPath)
    {
        // the categoryPath value would be
        // "household/kitchen/cookware/cooksets/nonstick". Process it (for ex. split it)
        // and then decide what you do..
        return View();
    }
+10

MVC , , , . , " ", "shop/products", "{category}/{subcategory}/{specialty}" ..

, , , . , URL- MVC, , , , .

- , Action, Id , , , , .

+2

Source: https://habr.com/ru/post/1696437/


All Articles