2

Assuming I have a specific problem which I need to remove some dataannotations's required attributes, how can I do this?

I know about view-model but I don't want to use it for some reasons.

MuriloKunze
  • 15,195
  • 17
  • 54
  • 82

2 Answers2

6

If you just want to disable validation for a single field in client side then you can override the validation attributes as follows:

@Html.TexBoxFor(model => model.SomeValue,                  
new Dictionary<string, object> { { "data-val", false }}) 

Here is the source for more answers

Community
  • 1
  • 1
TRR
  • 1,637
  • 2
  • 26
  • 43
  • 3
    your can use `@Html.TexBoxFor(model => model.SomeValue, new {data_val = false})` and the compiler is smart enough to convert the '_' to '-' – Nadeem Khedr Apr 18 '12 at 13:34
1

this will disable the validations on certain elements based on a selector

var validationSettings = $.data($('#formToValidateId').get(0), 'validator').settings;  
validationSettings.ignore = '.ignore';  

check this blog for more info

Nadeem Khedr
  • 5,273
  • 3
  • 30
  • 37