I want to extend MVC with helpers. Let's assume I want to build an extension method that takes a property from the model and renders a paragraph.
I've written this code, but it won't compile. I didn't figure out how to do it:
public static class PExtension
{
public static string PFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression) where TModel: class
{
var f = expression.Compile();
// won't compile the line below:
string propretyValue = f();
return "<p>" + propretyValue + "</p>";
}
}
For the record, my view should use something like:
@Html.PFor(m => m.Description);
Thanks.
EDIT
Error Description: *Delegate 'Func' does not take 0 arguments*