1

我有一个控制器中的下方设置了面向公众的网页生成与剃刀asp.net mvc4 ActionLink的语义URL查看

Company -> About -> Partners(我想为公司/公司/合作伙伴被访问) 链接行动方法

public about(string category) 
{ 
    ViewBag.Category = category; 
    return View(); 
} 

产生是因为低于该做的是让我有错误的URL

@Html.ActionLink("Partners & Investors", "About", "Company",new { Category = "Partners" },null) 

错误的URL

Company/About?Category=Partners%20and%20Investors

所以现在的问题是如何产生一个正确的网址,我想要的。我该怎么办 ?当你创建新的route并把它放在正确的位置

+0

@AndrewBarber嗨安德鲁我想一个url'公司/公司/ category'但它产生'公司/企业?类别= value'你能给一些投入 – Deeptechtons

回答

2

网址将被产生automatically

添加

事情是这样的:

routes.MapRoute(
    "Category", 
    "Company/About/{category}", 
    new { controller = "Company", action = "About", category = "default" } 
); 

// default 
routes.MapRoute(
    "Default", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
); 

而且看这个链接:Advanced Routing

+0

哇它的工作。我认为在使用它们之前,路线需要在路线图中定义。谢谢 – Deeptechtons