我怀疑某处有一些隐藏的魔法阻止了 T4MVC 中所有看起来像实际的方法调用。然后我的视图编译失败,stackTrace 进入了我的实际方法。
[Authorize]
public string Apply(string shortName)
{
if (shortName.IsNullOrEmpty())
return "Failed alliance name was not transmitted";
if (Request.IsAuthenticated == false || User == null || User.Identity == null)
return "Apply authentication failed";
Models.Persistence.AlliancePersistance.Apply(User.Identity.Name, shortName);
return "Applied";
}
所以这个方法毕竟不是在模板中生成的。
<%=Ajax.ActionLink("Apply", "Apply", new RouteValueDictionary() { { "shortName", item.Shortname } }, new AjaxOptions() { UpdateTargetId = "masterstatus" })%>
<%=Html.ActionLink("Apply",MVC.Alliance.Apply(item.Shortname),new AjaxOptions() { UpdateTargetId = "masterstatus" }) %>
第二种方法在编译时引发了异常,因为Apply
我的控制器中的方法具有一个[Authorize]
属性,因此如果未登录的人单击此属性,他们将被重定向到登录,然后直接返回此页面。在那里他们可以再次单击应用,这次是登录。
是的,我意识到一个是Ajax.ActionLink
,另一个是Html.ActionLink
我确实在 T4MVC 版本中尝试过它们。