Skip to content

Commit

Permalink
Merge pull request #152 from fsateler/partialfor-prefix
Browse files Browse the repository at this point in the history
Partials: Correctly set the HtmlFieldPrefix of the partial view
  • Loading branch information
robdmoore authored Jan 28, 2017
2 parents 9890b10 + f366668 commit bf0521d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChameleonForms/Component/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,15 @@ public static IHtmlString Partial<TModel>(this ISection<TModel> section, [AspMvc
public static IHtmlString PartialFor<TModel, TPartialModel>(this ISection<TModel> section, Expression<Func<TModel, TPartialModel>> partialModelProperty, [AspMvcPartialView] string partialViewName)
{
var formModel = (TModel)section.Form.HtmlHelper.ViewData.ModelMetadata.Model;
var expressionText = ExpressionHelper.GetExpressionText(partialModelProperty);

var viewData = new ViewDataDictionary(section.Form.HtmlHelper.ViewData);
viewData[WebViewPageExtensions.PartialViewModelExpressionViewDataKey] = partialModelProperty;
viewData[WebViewPageExtensions.CurrentFormViewDataKey] = section.Form;
viewData[WebViewPageExtensions.CurrentFormSectionViewDataKey] = section;
viewData.TemplateInfo = new TemplateInfo {
HtmlFieldPrefix = section.Form.HtmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText),
};
return section.Form.HtmlHelper.Partial(partialViewName, partialModelProperty.Compile().Invoke(formModel), viewData);
}
}
Expand Down
4 changes: 4 additions & 0 deletions ChameleonForms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ public static IHtmlString Partial<TModel>(this IForm<TModel> form, [AspMvcPartia
public static IHtmlString PartialFor<TModel, TPartialModel>(this IForm<TModel> form, Expression<Func<TModel, TPartialModel>> partialModelProperty, [AspMvcPartialView] string partialViewName)
{
var formModel = (TModel) form.HtmlHelper.ViewData.ModelMetadata.Model;
var expressionText = ExpressionHelper.GetExpressionText(partialModelProperty);
var viewData = new ViewDataDictionary(form.HtmlHelper.ViewData);
viewData[WebViewPageExtensions.PartialViewModelExpressionViewDataKey] = partialModelProperty;
viewData[WebViewPageExtensions.CurrentFormViewDataKey] = form;
viewData.TemplateInfo = new TemplateInfo {
HtmlFieldPrefix = form.HtmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText),
};
return form.HtmlHelper.Partial(partialViewName, partialModelProperty.Compile().Invoke(formModel), viewData);
}

Expand Down
2 changes: 1 addition & 1 deletion ChameleonForms/PartialViewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IFieldGenerator GetFieldGenerator<T>(Expression<Func<TPartialModel, T>> p
{
using (new SwapHtmlHelperWriter<TModel>(_parentForm.HtmlHelper, _partialViewHtmlHelper.ViewContext.Writer))
{
return new DefaultFieldGenerator<TModel, T>(_parentForm.HtmlHelper, _partialModelProperty.Combine(property), Template);
return _parentForm.GetFieldGenerator(_partialModelProperty.Combine(property));
}
}

Expand Down

0 comments on commit bf0521d

Please sign in to comment.