parent
90b07a9e9a
commit
4e7d1a5a32
|
|
@ -20,7 +20,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
[HtmlTargetElement("partial", Attributes = "name", TagStructure = TagStructure.WithoutEndTag)]
|
[HtmlTargetElement("partial", Attributes = "name", TagStructure = TagStructure.WithoutEndTag)]
|
||||||
public class PartialTagHelper : TagHelper
|
public class PartialTagHelper : TagHelper
|
||||||
{
|
{
|
||||||
private const string ForAttributeName = "asp-for";
|
|
||||||
private readonly ICompositeViewEngine _viewEngine;
|
private readonly ICompositeViewEngine _viewEngine;
|
||||||
private readonly IViewBufferScope _viewBufferScope;
|
private readonly IViewBufferScope _viewBufferScope;
|
||||||
|
|
||||||
|
|
@ -40,7 +39,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An expression to be evaluated against the current model.
|
/// An expression to be evaluated against the current model.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HtmlAttributeName(ForAttributeName)]
|
|
||||||
public ModelExpression For { get; set; }
|
public ModelExpression For { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -102,7 +100,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
// Determine which ViewData we should use to construct a new ViewData
|
// Determine which ViewData we should use to construct a new ViewData
|
||||||
var baseViewData = ViewData ?? ViewContext.ViewData;
|
var baseViewData = ViewData ?? ViewContext.ViewData;
|
||||||
|
|
||||||
// Use the rendering View's model only if an asp-for expression does not exist
|
// Use the rendering View's model only if an for expression does not exist
|
||||||
var model = For != null ? For.Model : ViewContext.ViewData.Model;
|
var model = For != null ? For.Model : ViewContext.ViewData.Model;
|
||||||
var newViewData = new ViewDataDictionary<object>(baseViewData, model);
|
var newViewData = new ViewDataDictionary<object>(baseViewData, model);
|
||||||
var partialViewContext = new ViewContext(ViewContext, view, newViewData, writer);
|
var partialViewContext = new ViewContext(ViewContext, view, newViewData, writer);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@using HtmlGenerationWebSite.Models
|
@using HtmlGenerationWebSite.Models
|
||||||
@model IList<Product>
|
@model IList<Product>
|
||||||
|
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<label asp-for="@Model[i].HomePage" class="product"></label>
|
<label asp-for="@Model[i].HomePage" class="product"></label>
|
||||||
<input asp-for="@Model[i].HomePage" type="url" size="50" disabled="disabled" readonly="readonly" />
|
<input asp-for="@Model[i].HomePage" type="url" size="50" disabled="disabled" readonly="readonly" />
|
||||||
</div>
|
</div>
|
||||||
<partial name="_ProductPartial" asp-for="@Model[i]" />
|
<partial name="_ProductPartial" for="@Model[i]" />
|
||||||
}
|
}
|
||||||
@* Print the HtmlFieldPrefix outside of the partial tag helper to ensure it hasn't been modified *@
|
@* Print the HtmlFieldPrefix outside of the partial tag helper to ensure it hasn't been modified *@
|
||||||
<div>HtmlFieldPrefix = @ViewData.TemplateInfo.HtmlFieldPrefix</div>
|
<div>HtmlFieldPrefix = @ViewData.TemplateInfo.HtmlFieldPrefix</div>
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|
||||||
<h3>@Html.DisplayFor(m => m.City)</h3>
|
<h3>@Html.DisplayFor(m => m.City)</h3>
|
||||||
<partial name="_EmployeePartial" asp-for="Employee" />
|
<partial name="_EmployeePartial" for="Employee" />
|
||||||
Loading…
Reference in New Issue