我在我的MVC 4
项目中有这个简单的用户Area
。MVC ActionLink触发RouteConstraint?
public class UserAreaRegistration : AreaRegistration
{
public override string AreaName { get { return "User"; } }
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute("User_Constraint",
"{userName}/{controller}/{action}/{id}",
new { userName = string.Empty, controller = "Products", action = "Index", id = UrlParameter.Optional },
new { userName = new UserNameRouteConstraint() },
new[] { "T2b.Web.Areas.User.Controllers" }
);
}
}
为了确保用户名存在,我有一个名为RouteConstraint
UserNameRouteConstraint()
这一切都在我的用户表一个简单的查找,如果用户已经发现返回true。
到目前为止好,这个建设工作正常!
现在;我在用户Area
视图具有代码
@Html.ActionLink("More information", "details", new {id = product.Guid})
以下行此单行导致被称为UserNameRouteConstraint()
....
如何以及为什么!?如果我用普通的HTML
编写链接(请参见下面的示例),它可以很好地工作,但我希望尽可能接近MVC
原则。
<a href="/username/Products/details/@product.Guid">More information</a>
有没有办法阻止RouteConstraint
的调用?
您的纯HTML()的外观如何? –
我已经添加了'HTML'行...只是简单的'HTML' :-) – 321X
你正在为{userName}传递“username”。它将需要名称为“用户名”的用户存在。它提供了什么? –