2013-07-07 78 views
0

Url重寫代碼以用於asp.net MVC4;我在代碼中使用App_Start/RouteConfig.cs。asp.net mvc4 url​​重寫爲seo

routes.MapRoute(
name: "subjectSefLink", 
url: "{controller}/{seo}/{page}", 
defaults: new 
{ 
    controller = "subject", 
    action = "Index", 
    seo = UrlParameter.Optional, 
    page = UrlParameter.Optional 
}); 

我使用控制器;

public class SubjectController : Controller 
{ 

    public ActionResult Index(string seo, int page) 
    { 
     return View(); 
    } 

} 

但不起作用;代碼的輸出= 404未找到

回答

1

您必須聲明int page變量爲nullable。在路由中,您已聲明page變量爲Optional。所以,在控制器中的動作方法應該是這樣的

public class SubjectController : Controller 
{ 
    public ActionResult Index(string seo, int? page) 
    { 
     return View(); 
    } 
} 
+0

不工作... 404找不到 – FatalError