2010-10-24 38 views

回答

1

你需要一個定製的輔助方法,此:

public static class HtmlExtensions 
{ 
    public static MvcHtmlString MyHelper<TModel, TValue>(
     this HtmlHelper<TModel> htmlHelper, 
     Expression<Func<TModel, TValue>> expression 
    ) 
    { 
     if (htmlHelper.ViewContext.HttpContext.User.Identity.IsAuthenticated) 
     { 
      return htmlHelper.EditorFor(expression); 
     } 
     return htmlHelper.DisplayFor(expression); 
    } 
} 

及用途:

<%: Html.MyHelper(x => x.SomeValue) %> 
+0

我以爲,謝謝! – Marcus 2010-10-26 05:53:17