Im using asp.net mvc 2.0. I have the following HtmlHelper extension:
AdminOnly(HtmlHelper helper, IPrincipal User, string htmlToRender)
{
//Render Html if have admin access.
}
I need to modify it to use in such a way: AdminOnly(User).TextBoxFor(x=>x.MyField) So that it could render edit field for MyField only if user has admin access.
For now Ive come out with the following solution:
AdminOnly(this MvcHtmlString resString, IPrincipal User)
{
//Render Html if have admin access.
}
So in code I can write things like:
<%:Html.TextBoxFor(x=>x.MyProperty).AdminOnly(User)%>
It works but I would like to be able to add more inputs or more flexibility to add text before and after the inputs, like this:
<%:Html.PlainText("Set your age: ").TextBoxFor(x=>x.Age).AdminOnly(User)%>
or
<%: Html.AdminOnly("Set your age: ", User).AddTextBoxFor(x=>x.Age)%>