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

TagHelper [asp-validation-for] doesn't work on server side #4277

Closed
John0King opened this issue Mar 13, 2016 · 5 comments
Closed

TagHelper [asp-validation-for] doesn't work on server side #4277

John0King opened this issue Mar 13, 2016 · 5 comments
Milestone

Comments

@John0King
Copy link

This is the code i write:

<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"  />

And this is the code that Generated:

<input name="Title" class="form-control input-validation-error" id="Title" type="text" value="sfdsfd" data-val="true" data-val-length-max="2" data-val-length="字段 Title 必须是最大长度为 2 的字符串。">
 <span class="text-danger field-validation-error" data-valmsg-replace="true" data-valmsg-for="Title">
</span>
@dougbu
Copy link
Contributor

dougbu commented Mar 13, 2016

If the actual generated HTML is <span ... />, everything is behaving as expected. The error message isn't visible because the self-closing element has no body.

Change the source to

...
<span asp-validation-for="Title" class="text-danger"></span>

@John0King
Copy link
Author

Is this a bug of visual studio web tools ?

@dougbu
Copy link
Contributor

dougbu commented Mar 13, 2016

We've had a few discussions related to this experience and aspnet/Tooling#398 remains open. But the onus today is on .cshtml authors; they must not write a normal HTML element as self-closing.

Side note: aspnet/Tooling#398 is about the opposite problem: VS does not warn when users write a void element with an end tag e.g. <input ...></input>.

@John0King
Copy link
Author

I think Razor View is missing some usefule method:

//get  every error message of  Model's property
public IEnumerable<string> GetModelErrorsFor( Action<model> action )
// get single error message of Model's property , sometimes i want  show only one error
public string GetFirstModelErrorFor(Action<model> action)
// get validation-summary
public IEnumerable<string> GetModeErrors( ValidationSummary options )

// and also  DisplayNameFor 

those method work like HtmlHelpers or TagHelpers , but they only return pure string rather than full HTML mark; So we can use them in any cases!

@Eilon Eilon added this to the Backlog milestone Mar 15, 2016
@Eilon
Copy link
Contributor

Eilon commented Mar 15, 2016

Moving to backlog.

@danroth27 danroth27 changed the title TagHelper [asp-validation-for] doesn't work on server sider ? TagHelper [asp-validation-for] doesn't work on server side Jul 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants