【问题标题】:asp.net mvc4 url rewrite for seo用于 seo 的 asp.net mvc4 url​​ 重写
【发布时间】:2013-07-04 20:48:21
【问题描述】:

用于 asp.net MVC4 的 URL 重写代码;我用 App_Start/RouteConfig.cs 中的代码下来。

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 not found

【问题讨论】:

    标签: asp.net-mvc url url-rewriting asp.net-mvc-routing


    【解决方案1】:

    您必须将int page 变量声明为nullable。与路由一样,您已将page 变量声明为Optional。所以,controller中的action方法应该是这样的

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

    【讨论】:

      猜你喜欢
      • 2011-11-27
      • 2013-09-11
      • 2014-06-28
      • 2014-04-11
      • 2013-04-18
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      相关资源
      最近更新 更多