Search code examples
asp.net-mvcvalidationrazorunobtrusive-validation

MVC & jQuery Validate, different HTML output on localhost vs live


A very simple example with something strange going on. Never noticed it before, but this is the first time I've looked.

Got myself a model with a field like:

[Display(Name = "Full Name")]
[Required(ErrorMessage = "Please enter your Full name")]
[RegularExpression(@"^((\b[a-zA-Z]{2,40}\b)\s*){2,}$", ErrorMessage = "Please enter your first and last name.")]
public string FullName { get; set; }

Razor view:

<div class="form-group">
@Html.TextBoxFor(m => m.FullName, new { placeholder = "Full Name", @Class = "form-control input-sm" })
@Html.ValidationMessageFor(m => m.FullName)
</div>

When I submit an invalid form, I get an error message as I should... but the HTML is different on localhost than on the server.

Localhost gives me a span id="FullName-error" with some aria tags. Live server gives me a span for="FullName", without aria tags. The files on production are nothing more than a Publish and Upload.

My localhost generates the following (this is inspecting it in the chrome debug window):

<div class="form-group">
<input class="form-control input-sm input-validation-error" data-val="true" data-val-regex="Please enter your first and last name." data-val-regex-pattern="^((\b[a-zA-Z]{2,40}\b)\s*){2,}$" data-val-required="Please enter your Full name" id="FullName" name="FullName" placeholder="Full Name" type="text" value="" aria-required="true" aria-invalid="true" aria-describedby="FullName-error">
<span class="field-validation-error" data-valmsg-for="FullName" data-valmsg-replace="true">
<span id="FullName-error" class="">Please enter your Full name</span>
</span>
</div>

The live server generates the following:

<div class="form-group">
<input class="form-control input-sm input-validation-error" data-val="true" data-val-regex="Please enter your first and last name." data-val-regex-pattern="^((\b[a-zA-Z]{2,40}\b)\s*){2,}$" data-val-required="Please enter your Full name" id="FullName" name="FullName" placeholder="Full Name" type="text" value="">
<span class="field-validation-error" data-valmsg-for="FullName" data-valmsg-replace="true">
<span for="FullName" generated="true" class="">Please enter your Full name</span>
</span>
</div>

Anyone have any thoughts or can hint at what's going on?


Solution

  • Seems something is changed while publishing the web application.

    I think version of jQueryValidate is problem, please refer What is the "generated" attribute seen in some HTML tag used for?