You need to use @Html.TextBoxFor to bind textbox with the model's field. Doing that will also enforce client-side validation if any specified within model.
@Html.TextBox does not bind text box with the model property (i.e. field), and thus, validation not firing up in first case.
You need to use @Html.TextBoxFor to bind textbox with the model's field. Doing that will also enforce client-side validation if any specified within model.
@Html.TextBox does not bind text box with the model property (i.e. field), and thus, validation not firing up in first case.
Thanks, sorted I need to change the name of the form element to get everything to submit as one cascading model, but I can use @Html.TextBoxFor(model => model.CategoryTextFieldBridges[0].TextFields.Name, new { Name = "CategoryTextFieldBridges[0].TextFields.Name"
})
EnenDaveyBoy
Participant
1465 Points
1147 Posts
client site validation not working
Mar 22, 2012 12:55 AM|LINK
If I use the script below, client side Validation doesn't work, but server side does
<p>
@Html.LabelFor(model => model.Name)
<span class="editor-field">
@Html.TextBox("CategoryTextFieldBridges[0].TextFields.Name", null, new { @class = "text-box single-line" })
@Html.ValidationMessage("CategoryTextFieldBridges[0].TextFields.Name")
</span>
</p>
however if I use
<p>
@Html.LabelFor(model => model.CategoryTextFieldBridges[0].TextFields.Name)
<span class="editor-field">
@Html.EditorFor(model => model.CategoryTextFieldBridges[0].TextFields.Name)
@Html.ValidationMessageFor(model => model.CategoryTextFieldBridges[0].TextFields.Name)
</span>
</p>
Client side validation does work, they both product the same HTML, so why isn't the first example working the client side validation?
nirman.doshi
Participant
1520 Points
775 Posts
Re: client site validation not working
Mar 22, 2012 06:05 AM|LINK
You need to use @Html.TextBoxFor to bind textbox with the model's field. Doing that will also enforce client-side validation if any specified within model.
@Html.TextBox does not bind text box with the model property (i.e. field), and thus, validation not firing up in first case.
Software Developer
Vadodara, India
dharnendra
Contributor
2955 Points
551 Posts
Re: client site validation not working
Mar 22, 2012 06:49 AM|LINK
Did you added below 2 keys in web.config
Technical Leader
GTL-Ahmedabad
EnenDaveyBoy
Participant
1465 Points
1147 Posts
Re: client site validation not working
Mar 22, 2012 03:57 PM|LINK
EnenDaveyBoy
Participant
1465 Points
1147 Posts
Re: client site validation not working
Mar 22, 2012 04:15 PM|LINK