UPDATE: Actually this thing has several uses, but rather than spend time listing them I’ll invite [polite] suggestions how it can be used… Smile

Here’s a small MVC extension method that looks useful, but might be totally redundant:

public static void RenderPartial<TModel, TProperty>( this HtmlHelper<TModel> helper, string partialViewName, Expression<Func<TModel, TProperty>> expression )
{
    var model = (TModel)helper.ViewData.Model;
    var childModel = expression.Compile()( model );
    var viewData = new ViewDataDictionary<TProperty>( childModel );
    viewData.TemplateInfo.HtmlFieldPrefix = ExpressionHelper.GetExpressionText( expression );

    helper.RenderPartial( partialViewName, childModel, viewData );
}

Basically it’s the same as the regular Html.RenderPartial but you can pass your model as an expression.  It’ll handle getting the field name prefixes etc. automatically.

I’m pretty sure the same thing can be achieved with Html.EditorFor and Html.DisplayFor (possibly with better performance too, depending on if they take the Compile() hit or not).  However I could be wrong, so I posted it anyway Smile

DotNetKicks Image