Open Bartmax opened 9 years ago
Yes, once again Microsoft develops a feature to fix a bug. When will they learn?
Why on earth do we need more magic strings in our html, seems 2 steps backward. And please spare me for prefixing the tag-helpers so we can distinguish them.
More magic @im-an-attribute-that-runat-server=true?. Please stop our pain, seems that people got wiped their brains... anyone even remember WebForms?
Back then it was clear what run at server actually did, you either liked it or hated it, but nevertheless it made the butter for our bread.
It would be a lot better if Microsoft looked at T4MVC and tried to learn something about how developers would like to eat code.
T4MVC is a T4 template for ASP.NET MVC apps that creates strongly typed helpers that eliminate the use of literal strings in many places.
e.g. instead of
@Html.ActionLink("Delete Dinner", "Delete", "Dinners", new { id = Model.DinnerID }, null)
T4MVC lets you write
@Html.ActionLink("Delete Dinner", MVC.Dinners.Delete(Model.DinnerID))
I fully agree with the idea of get rid of 'magic strings'!! @Bartmax proposal have a good balance between embrace HTML standards and still make use of server side compile time features.
After using for a while, I had to say that I like the current version of TH better than my proposal. The only thing may have a place is the use of href instead of asp-action/asp-controller. but currently, th are awesome.
I'm pretty sure this is coming too late, it's ok. After playing around I want to suggest minor modifications to the current proposal.
TL;DR There are two suggestion here: Syntactic sugar & the removal of special attributes that targets existing attributes (like having an
action
andcontroller
attributes for an existinghref
[anchor tag example]). And some crazy things as bonus ;)So, instead of using asp specific tags, one can use existing tags (when they exist) and apply some char suggesting to be resolved by tag helpers. ($ is used here for demonstration purposes only).
this simple input, will render the input with the value of Model.Age and the correct
type
(number in this case) andname
if not specified. I can still override the html if I provide a type. The idea here is that tag helpers doesn't get in my way of me authoring the html.this get no modification, there's no tag for validation so it's ok to go with a span (or any tag) and use asp- specific annotation. but the asp- is not required, more on that later.
This will of course create the input for the Model.Password property. I can do write text outside the {} like:
the benefit of the above is clear on the form tag:
Instead of using controller and action, I more forward using html5 existing types. the $ hints razor that this is generated via a tag helper.
Tag helpers could then be defined with: tag.attr (example: form.action, a.href, button.type, etc) attr (example class, value, type, style, etc) and maybe: tag.tag.attr (but i dont find a good example).
This definitions will not only help in throwing errors when a tag helper is used where it shouldn't but also for intellisense (usefull when one is authoring tag helpers)
Tag helpers in this way won't need the asp- prefix because if there's a $ at the start, it means it should try to get a tag helper for that attr, so in the case of
<span asp-validation-for="UserName" class="text-danger"></span>
we can safe write :still, the asp- can be supported in the sense that you can do asp-tag and you don't need to specify the $ character. so both scenarios apply.
both are valid and should output the same results.
I don't see it as a major difference on how they are implemented now, except maybe for the form tag, but for me it looks like more html, not obscure on when is asp or not processing the data, and less verbose with less
asp-
strings.another interesting important technique that can be used is intellisense, lets take a look at the anchor tag.
When we write
<a href="$
<--- here we can retrieve intellisense for all actions in all controllers and narrowing down as we type, much like project.json autocomplete works.More crazy or future things we can do
As I pointed out, I know, kinda late to the party, but maybe someone find something valuable here.