Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Cannot use tag helpers asp-for in editor or display templates (cannot leave asp-for empty). #3996

Closed
rwasef1830 opened this issue Jan 26, 2016 · 5 comments

Comments

@rwasef1830
Copy link

Hello,
When trying to use tag helpers in display or editor templates, example:

Views/Shared/EditorTemplates/DateTime.cshtml:

@model DateTime?

<input asp-for="" type="text" />

I get an error stating that asp-for is a tag helper bound value to a type of ModelExpression and it cannot be null or whitespace. But there is a valid use case for passing an empty asp-for attribute which is the functional analogue of:

@model DateTime?

@Html.Textbox(string.Empty)

Which simply uses the model prefix in the name and id attributes.

The alternative would be a new asp-for-model valueless attribute on the existing tag helpers to allow this functionality. Allowing this will allow the best of both the tag helpers and templated helpers to be used at once.

Until then, I am forced to use the ancient helpers in my complex editor templates.
Thanks for considering this and let me know if you need any further info.

@danroth27
Copy link
Member

You should be able to do asp-for="@Model", but there is another issue blocking that usage: #3978. Closing this issue since we don't plan to support asp-for="".

@seraphx2
Copy link

So we can, or we cannot, use asp-for tag helpers in Display/Edit templates?
Because it's now almost 2018 and these asp-for's are not working in my template.
Seems lame to come up with this whole idea that supplants the old HTML helpers and then to just definitively say: "nah, but we aren't going to support it here".

@NTaylorMullen
Copy link
Contributor

@seraphx2 you're correct, they currently aren't supported for display/editor templates. However, @DamianEdwards has done work to provide TagHelper editor template implementations that do work. Take a look at his repo.

@seraphx2
Copy link

Thanks. I'll take a look.

@brackers17
Copy link

Are tag helpers now supported in display/editor templates? I notice they appear to be working but not providing the correct name attributes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants