Is it possible to render the editortemplates if a user is logged on and the displaytemplates as a default or do I need to create my own Html helper extension?
A:
You need a custom helper method for this:
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);
}
}
And use:
<%: Html.MyHelper(x => x.SomeValue) %>
Darin Dimitrov
2010-10-25 06:33:01
I assumed, thanks!
Marcus
2010-10-26 05:53:17