-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a <partial /> Tag Helper #5916
Comments
I like the partial TagHelper idea 👍 would love to be able to pass a predicate/action the would be evaluated at runtime to either render the partial or not; eg. <partial name="userProfilePartial" predicate="namespace.staticClass.predictionOrAction"> |
Moving out of the milestone just so that we pick it up in triage. But yeah this looks good. |
this is very similar to the body of work that i'm up against right now with a little bit of a difference in capability... i'm looking to meld the concepts of a tag helper (having content within it in the html itself) with the concepts of perhaps i'm way too far out there for what you guys are talking about but consider the potential for the following:
(or as follows as you're describing:)
where the big idea here is that each of these TagHelpers has the inherent capability of loading some partial as you're describing, but also the ability to inject the template that it was wrapped around, in this case the two partial TagHelpers within the the 'trick' here is in how you dictate to the what do you all think about that? |
Why not: [HtmlTargetElement("partial", Attributes = "name")]
public class PartialTagHelper : TagHelper
{
private readonly IHtmlHelper _htmlHelper;
public PartialTagHelper(IHtmlHelper htmlHelper)
{
_htmlHelper = htmlHelper;
}
[ViewContext]
public ViewContext ViewContext { get; set; }
public string Name { get; set; }
[HtmlAttributeName("asp-for")]
public ModelExpression For { get; set; }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
((IViewContextAware)_htmlHelper).Contextualize(ViewContext);
ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = For.Name;
var content = await _htmlHelper.PartialAsync(Name, For.Model);
output.TagName = null;
output.Content.SetHtmlContent(content);
}
} TemplateInfo.HtmlFieldPrefix can keep a full name if I render an input on partial view. |
See the Tag Helper Pack and #6512. |
Q: shouldn’t Async methods have an optional CancellationToken with the default of default(CancellationToken.None) ? |
@grahamehorner I'm not sure what the context of your question is? Is this about the missing |
look at source of a number of TagHelper the ProcessAsync doesn't seem to take a cancellation token; which I would have expected to see to allow clear up on the TagHelper when the pipeline/caller is cancelled. |
Right now, there are four methods on
IHtmlHelper
for rendering partials, and it isn't clear to users if one is better than the other.RenderPartialAsync
is certainly much harder to call and looks much uglier at the call site.All of these methods also have an overload that accepts a model object, e.g.
@await Html.PartialAsync("_AnalyticsBody", SomeModel)
It would be much nicer to have a Tag Helper for partial rendering that just does "the right thing":
Strawman implementation:
@NTaylorMullen @rynowak @pranavkm @Eilon
The text was updated successfully, but these errors were encountered: