What I'm trying to do is create an extension method for the HtmlHelper to create a specific output and associated details like TextBoxFor<>. What I want to do is specify the property from the model class as per TextBoxFor<>, then an associated controller action and other parameters.
So far the signature of the method looks like:
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 issue occurs when I go to call it. In my view if I call it as per the TextBoxFor without specifying the Model type I am able to specify the lambda expression to set the property which it's for, but when I go to specify the action I am unable to.
However, when I specify the controller type Html.Create<HomeController>( ... )
I am unable to specify the model property that the control is to be created for.
I want to be able to call it like
<%= Html.Create<HomeController>(x => x.Title, controller => controller.action, null) %>
I've been hitting my head for a few hours now on this issue over the past day, can anyone point me in the right direction?
Edit: Thanks for the responses to this.
So without specifying all of the types I think I can live with
<%= Html.Create(x => x.Title, ((HomeController)controller) => controller.action, null) %>
But still need the reference to the action, not the actual action itself
*back to thinking :)
Edit #2:
I'm starting to think trying to make it purely strongly typed is a bit far fetched. Going along the same lines as the provided html helper extension methods maybe just specifying the action name and controller name as string parameters is the way to go?! But surely what I'm trying to do is possible? hits head