ASP.NET MVC 3路由 [英] ASP.NET MVC 3 routing
本文介绍了ASP.NET MVC 3路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建航线。
这是
/emlak/TITLE/number.aspx
如
/emlak/Here_is_your_best_property/123456.aspx
Global.asax中:
Global.asax:
routes.MapRoute(
"Product",
"{controller}/{deli}/{productId}",
new { controller = "emlak", action = "Index" },
new { productId = UrlParameter.Optional , deli = UrlParameter.Optional }
);
我控制器
namespace emrex.Controllers
{
public class EmlakController : Controller
{
//
// GET: /Emlak/
public ActionResult Index(String productId, String deli)
{
return View();
}
}
}
和我得到一个错误:
在/应用程序中的服务器错误。
Server Error in '/' Application.
资源无法找到。
感谢您的帮助。
推荐答案
您的问题是(至少当我想你的code)你有指定的路由约束,他们真的不应该。我能得到这个通过做工作得很好:
Your problem is (at least when I tried your code) you have route constraints specified where they really shouldn't be. I was able to get this to work just fine by doing:
routes.MapRoute(
"Product",
"{controller}/{deli}/{productId}",
new { controller = "emlak", action = "Index", productId = UrlParameter.Optional, deli = UrlParameter.Optional }
);
尝试 - ?有什么区别
Try that - any difference?
这篇关于ASP.NET MVC 3路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文