What I'm trying to do is create an extension method for the HtmlHelper to create specific output and related details like TextBoxFor <>. I want to specify a property from a model class according to TextBoxFor <>, then the controller action associated with it and other parameters.
So far, the method signature has looked like this:
public static MvcHtmlString Create<TModel, TProperty, TController>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, Expression<Action<TController>> action, object htmlAttributes) where TController : Controller where TModel : class
The problem arises when I go to a call. In my opinion, if I name it according to TextBoxFor without specifying the type of model, I can specify a lambda expression to set the property for which it is intended, but when I go to indicate an action that I cannot.
However, when I specify the type of the controller Html.Create<HomeController>( ... ) , I cannot specify the model property for which the control should be created.
I want it to be called as
<%= Html.Create<HomeController>(x => x.Title, controller => controller.action, null) %>
I’ve been banging my head on this issue for several hours over the last day, can someone point me in the right direction?
Edit: Thanks for the answers to this.
Therefore, without specifying all types, I think I can live with
<%= Html.Create(x => x.Title, ((HomeController)controller) => controller.action, null) %>
But still need a reference to the action, not the actual action
* back to thinking :)
Edit # 2:
I'm starting to think, trying to make it purely strongly typed, a little far-fetched. Performing the same lines as the provided html helper extension methods, perhaps just specifying the action name and controller name as the string parameters is the way to go! But of course, perhaps what am I trying to do? head hits