I have a model, which has a field that I don't want it to be validated on client side. Is there a way to turn off the client validation just on the referred field?
Asked
Active
Viewed 1,273 times
2
-
2Create and use a view model **specific to the view** ! – Shyju Feb 03 '16 at 23:01
-
Using a view model I think it is redundant for the situation I have. But thanks a lot for your answer. – viniciusalvess Feb 03 '16 at 23:05
-
1@viniciusalvess, Using a view model is NEVER redundant and is ALWAYS the recommend approach – Feb 03 '16 at 23:13
-
Its best you use a view model and don't add the '[Required]' attribute. – theanimashaun Feb 03 '16 at 23:29
-
I agrree with you @StephenMuecke , but I'm creating something simple, and the code repeating at the view model kind of bothers me. But thanks to you all that contributed ! – viniciusalvess Feb 04 '16 at 01:08
1 Answers
0
<div class="editor-field">
@{ Html.EnableClientValidation(false); }
@Html.TextBoxFor(m => m.BatchId, new { @class = "k-textbox" })
@{ Html.EnableClientValidation(true); }
</div>
Answer is from here: ASP .NET MVC Disable Client Side Validation at Per-Field Level

Community
- 1
- 1

Bruno Garcia
- 6,029
- 3
- 25
- 38
-
Thank you @Bruno Garcia that helps a lot. I found out setting the data-val atribute to false works too. But I think your aproach is more clear ! Example I found out : Html.TextBoxFor(model => model.banco.nome, new { class = "form-control", id = "pessoa_banco", placeholder = "Pesquisar...", data_val = false }) – viniciusalvess Feb 04 '16 at 01:05