2009-11-09 27 views

回答

1

MVC中的觀點背後的代碼被刪除,因爲它似乎並不符合MVC範例。也許你應該考慮creating your own Html Helpers。這樣做,擴展像Html.ActionLink()這樣的現有操作是很容易的(並且很有趣)。

這個例子顯示了我如何創建一個幫手來調整我的登錄/註銷鏈接。有些脂肪酶可能​​會認爲這是一個幫助一個良好的使用,但它爲我工作:

/// <summary> 
    /// For the global MasterPage's footer 
    /// </summary> 
    /// <returns></returns> 
    public static string FooterEditLink(this HtmlHelper helper, 
     System.Security.Principal.IIdentity user, string loginText, string logoutText) 
    { 
     if (user.IsAuthenticated) 
      return System.Web.Mvc.Html.LinkExtensions.ActionLink(helper, logoutText, "Logout", "Account", 
       new { returnurl = helper.ViewContext.HttpContext.Request.Url.AbsolutePath }, null); 
     else 
      return System.Web.Mvc.Html.LinkExtensions.ActionLink(helper, loginText, "Login", "Account", 
       new { returnurl = helper.ViewContext.HttpContext.Request.Url.AbsolutePath }, null); 
    } 

..和我這是怎麼使用它的觀點(部分觀點是精確的):

<% =Html.FooterEditLink(HttpContext.Current.User.Identity, "Edit", "Logout (" + HttpContext.Current.User.Identity.Name + ")")%>