Currently I am using a ViewModelFactory hanging off HtmlHelper in an extension method:
public static IViewModelFactory ViewModels(this HtmlHelper helper)
{
var factory = DependencyResolver.Current.GetService<IViewModelFactory>();
return factory;
}
A开发者_开发问答nd then an example view with partial:
@model WidgetViewModel
<fieldset>
@using (Html.BeginForm())
{
@Html.Partial("_Form.cshtml", Html.ViewModels().EventForm() )
}
</fieldset>
Is this a bad idea? It feels dirty. If so, where/how is the testable best practice to populate/build ViewModels for my Partials?
This totally breaks the pattern.
ViewModels should be supplied via the controller, not the view.
精彩评论