C#MVC路由检测
发布时间:2020-12-16 06:53:35 所属栏目:百科 来源:网络整理
导读:我需要打电话给客户资料页面,例如“(www.mysite.com/John)或(www.mysite.com/customer name)” 所以我添加了这样的路线 routes.MapRoute( name: "Profile",url: "{id}",defaults: new { controller = "Home",action = "Index",id = UrlParameter.Optional }
我需要打电话给客户资料页面,例如“(www.mysite.com/John)或(www.mysite.com/customer name)”
所以我添加了这样的路线 routes.MapRoute( name: "Profile",url: "{id}",defaults: new { controller = "Home",action = "Index",id = UrlParameter.Optional } ); routes.MapRoute( name: "Default",url: "{controller}/{action}/{id}",id = UrlParameter.Optional } ); 但它总是转到第一条路线,好像我需要打开它不起作用的任何控制器 谢谢. 解决方法
这条路线不会这样,所以你有两个选择
1)当您采取任何行动时,您的网址应为www.mysite.com/controller/action,否则会出现HTTP 404错误 2)您可以通过添加前缀www.mysite.com/Customer/John来使路由唯一 routes.MapRoute( name: "Profile",url: "Customer/{id}",action = "Index"} ); 你的行动应该是 public ActionResult Index(string id) { string SurveyName = ""; if (id != null) SurveyName = id; if (!string.IsNullOrEmpty(SurveyName)) { ViewBag.Survey = SurveyName; } return View(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |