2011-06-05 72 views
0

我有幫助的方法,如果用戶進行身份驗證這是隻檢查,但其發生錯誤自定義身份驗證助手類。需要幫助

Helper方法

public static bool IsLoggedIn(this HtmlHelper helper) 
    { 
     return helper.ViewContext.HttpContext.Request.IsAuthenticated; 
    } 

查看

@if (GH.IsLoggedIn) //Error is on this line 
{ 
    <div class="sign-text" >Signed In As @GH.IdentityName </div> 
} 

錯誤

Compiler Error Message: CS0428: Cannot convert method group 'IsLoggedIn' to non-delegate type 'bool'. Did you intend to invoke the method? 

有人告訴我最新的問題。

回答

2

你爲什麼woudn't這樣稱呼它@if (Html.IsLoggedIn()) { .. }

...

你可能想這個方法呈現,而不是在你看來做@if (...)檢查相應的HTML。

public static MvcHtmlString SignInText(this HtmlHelper htmlHelper) 
{ 
    // you code here 
} 

然後將其插入您的看法是這樣的:

@Html.SignInText() 
+0

感謝我的愚蠢。你能告訴我如何寫這個三元語句請@ Html.IsLoggedIn()?

Signed In As @Html.IdentityName
Pirzada 2011-06-05 23:18:27

+0

'@ Html.Raw(Html.IsLoggedIn()?「

Signed In as " + Html.Encode(Html.IdentityName) + "
」:String.Empty)' – 2011-06-05 23:35:24

+0

你想讓我在你的SignInText的HtmlHelp中使用上面的Singin鏈接。從視圖隱藏邏輯? – Pirzada 2011-06-06 00:37:11