MVC3路由问题(隐藏属性名称)
嘿! 我有这个控制器:
public ViewResult Hotel(string hotelSupplierCode, bool displayAllRooms, bool resend)
{
HotelModel model;
if (resend)
{
model = (HotelModel)Session["HotelDetails"];
HotelManager.ResendHotel(model.Hotel.Id);
model.Hotel.Status = 1;
}
else
{
model = HotelModel.GetGotel(hotelSupplierCode, displayAllRooms);
}
Session["HotelDetails"] = model;
return View("Hotel", model);
}
和这条路线:
routes.MapRoute(
"Hotel", // Route name
"{controller}/{action}/{hotelSupplierCode}/{displayAllRooms}/{resend}", // URL with parameters
new { controller = "Hotel", action = "Hotel", hotelSupplierCode = UrlParameter.Optional, displayAllRooms = UrlParameter.Optional, resend = UrlParameter.Optional }
问题是,当我访问视图时,返回的 URL 是这样的:
http://localhost:49575/Hotel/Hotel?hotelSupplierCode=3711&displayAllRooms=False&resend=False
但我想要这样的东西:
http://localhost:49575/Hotel/Hotel/3711/False/False
那么我如何隐藏属性名称?如果我手动输入第二个 URL,它就可以正常工作。
Hy!
I have this controller:
public ViewResult Hotel(string hotelSupplierCode, bool displayAllRooms, bool resend)
{
HotelModel model;
if (resend)
{
model = (HotelModel)Session["HotelDetails"];
HotelManager.ResendHotel(model.Hotel.Id);
model.Hotel.Status = 1;
}
else
{
model = HotelModel.GetGotel(hotelSupplierCode, displayAllRooms);
}
Session["HotelDetails"] = model;
return View("Hotel", model);
}
and this route:
routes.MapRoute(
"Hotel", // Route name
"{controller}/{action}/{hotelSupplierCode}/{displayAllRooms}/{resend}", // URL with parameters
new { controller = "Hotel", action = "Hotel", hotelSupplierCode = UrlParameter.Optional, displayAllRooms = UrlParameter.Optional, resend = UrlParameter.Optional }
The problem is that when I access the view the returned URL is soemthing like that:
http://localhost:49575/Hotel/Hotel?hotelSupplierCode=3711&displayAllRooms=False&resend=False
but I want something like that:
http://localhost:49575/Hotel/Hotel/3711/False/False
So how I can hide the atribute names? If i put the second URL manualy it works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑你的问题是由于你的路线顺序造成的。路由必须按照从最具体到最一般的顺序放置,通常以新项目中定义的默认路由结尾。
确保将酒店路线放置在默认路线之前。
I suspect that your issue is due to the order of your routes. Routes must be placed in order from the most specific to the most general, usually ending with the default route defined in a new project.
Make certain that you place the Hotel route before the default route.
尝试这样的路线
Try route like this