-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Unable to utilize ModelExpression with [HtmlAttributeName(DictionaryAttributePrefix = "myprefix-")] Dictionary #5310
Comments
@NTaylorMullen @DamianEdwards Is there any specific reason to not support this? |
MVC supports Further this is a rather large feature request with an unclear upside. With no enforced commonality between the dictionary values (beyond being lambda expressions), about all the tag helper could do is evaluate the expressions and convert them to
How is that relevant? |
Thanks for the quick responses @danroth27 & @dougbu... The use case centers around [strongly-typed] template generation for Angular 2. For example:
becomes...
Utilizing DictionaryAttributePrefix would enable a simple set of TagHelpers that correspond to Angular's binding syntax: https://angular.io/docs/ts/latest/guide/template-syntax.html#!#binding-syntax Being "generic" (e.g. ng-bind-XXX) would allow for any Component property being able to be bound in this way. This becomes especially important when targeting @input annotations on UI Components. For example:
becomes...
While I certainly appreciate the effort to support As far as my note regarding the razor tooling, I was simply pointing out that this issue was not surfaced until run time. Ideally, such "things" are flagged at design time. |
I'm still not understanding the value of generating |
My apologies, I was not asserting that
I need to get at the metadata for the Model's property. At a minimum, I need the property's name, but perhaps other metadata as I look to support more advanced templating scenarios. If I'm not mistaken, "@someTitleProperty" would simply yield that property's value, not its name (just tested and confirmed). Not to mention, that if the property was not a string (e.g. int),Razor seems to doing an implicit convert of int => string. In this case, someInt = 123 would generate |
Do you need both the property's name and it's value? I'd like to understand whether you need a |
I do not need the value... In fact, in all likelihood, I won't even have a controller given that the Component I've been referencing is being utilized in lieu of an actual controller. So, no So I understand, in the
|
Your requirements are now much more clear. They might be satisfied any number of ways e.g. a new This issue is currently in the backlog, meaning we would accept a well-written PR filling the gap. In the meantime, I'd recommend using a Your tag helper could also confirm the dictionary values match one of |
@dougbu, Thanks for the great exchange! The issue with @nameof is that you loose support for dot-notation:
Please pardon my ignorance, first time getting to this point. As for a PR, should I create one? is there a template? How to submit? Thanks again! |
I agree deeper properties get more complex when using the tag helper enforcement approach. Probasbly best to have users type in arbitrary dotted property names and recursively checking each segment (at runtime) in the tag helper. Note Feel free to create a PR. I suspect the core change will be in |
@dougbu confirmed that this ought to be fairly straight-forward to fix - it mostly consists of removing the exception and updating tests. |
I've just forked the repo and have begun to dig into the existing tests to see where best to incorporate then necessary test(s) as part of my TDD. I'm struggling to locate an existing set of tests that explicitly parses, generates AND renders the necessary markup. @dougbu, You were right... the heavy-lifting was in the tests! I was able to build out an specific TagHelper test (based on InputTagHelperTest for ModelExpression and FormTagHelperTest for prefix-value specification examples) which of course worked b/c the ModelExpression was explicitly added to the Dictionary of values annotated with In addition, I was able to adjust the Razor.Host test's ModelExpressionTagHelper.cshtml file to include an instance of my Any guidance would be greatly appreciated. I'd really like to run this down to completion. |
@cjrosa updating the tests using Note even that test will fail unless you change I suggest adding one similar functional test, extending the TagHelpersWebSite, that adds a couple of expressions to the dictionary. Not sure exactly what the new tag helper should do w/ the dictionary but fine as long as the response makes it obvious the expected entries are present. |
@cjrosa many thanks for finding this issue and then fixing it! |
I have also created a tag helper that uses a dictionary of types <string, ModelExpression>, and it works great. But when a view (.cshtml) that uses this taghelper is open in VS, building the solution still gives this output in the VS Error List: Error Invalid tag helper property 'SomeNamespace.SomeTagHelper.some-prefix'. Dictionary values must not be of type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression'. Is this some error in VS? I'll report it in the VS feedback tool as well. |
@deap82 can you please open a new issue on https://github.com/aspnet/Razor and include a screenshot of the error in the errors window. Posting feedback on a closed issue makes it really easy for us to lose track of it. |
@rynowak It's also posted here and got a "Triaged" state: https://developercommunity.visualstudio.com/content/problem/66937/vs-reports-invaliud-tag-helper-property-even-thoug.html |
Within razor, I've created the following:
<div myprefix-test="@Model.Value"></div>
I'd like to be able to create a tag helper with the following so I can create multiple [expression bound] attributes witht he same prefix.
However when running the application, I receive the following as runtime:
I should note that the razor tooling accepts the markup above.
Any thoughts would be greatly appreciated.
The text was updated successfully, but these errors were encountered: