开发者

Best Place To Populate ViewModels For Partials?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜