MVC URL路径选择的自定义网址 [英] MVC Url Routing For custom url

查看:124
本文介绍了MVC URL路径选择的自定义网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过像

http://localhost:24873/Jobs/[companyname]
or
http://localhost:24873/[companyname]/Jobs/ (Preferred)

我试过低于全球aspx文件路由和创建控制器命名乔布斯和乔布斯的文件夹Index操作的结果,但无法正常工作。

I tried below routing in global aspx file and created controller named Jobs and Index action result with Jobs folder but not working.

 routes.MapRoute(
             "JobList", // Route name
             "Jobs/{companyname}",
              new
              {
                  controller = "Jobs",
                  action = "Index",
                  companyname = string.Empty
              }
          );

和我的控制器:

public partial class JobsController : Controller 
{ 
    public ActionResult Index() 
    { 
          JobsListModel model = new JobsListModel(); 
          return View(model); 
    } 
}

我做错了吗?请帮助。

What I am doing wrong? Please help.

推荐答案

您必须添加这条路线在Global.asax中的第一项,否则将请求路由到默认路由(或之前的路线吧)

You must add this route as the first entry in global.asax, otherwise the request will be routed to the default route (or route before it)

来源

这篇关于MVC URL路径选择的自定义网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆