0

I'm using MVC3 and I have a model like this:

public class Foo
{
 [Required]
 [Range(0.01, 99.99)]       
 public double? f1{ get; set; }
}

And I want to ugnore javascript range validation, but keep the required javascript validation. How can I do that?

3
  • you can remove @html.validatefor() from your html code Commented Mar 21, 2012 at 8:50
  • but what about required? it wil be removed to. Commented Mar 21, 2012 at 8:55
  • yep there is a flaw in my logic. Commented Mar 21, 2012 at 9:04

2 Answers 2

2

I found solution, just removed some attributes from textbox:

$('#fieldId').removeAttr("data-val-range");
$('#fieldId').removeAttr("data-val-range-min");
$('#fieldId').removeAttr("data-val-range-max"); 
Sign up to request clarification or add additional context in comments.

Comments

1

if you dont want the range validation then simply remove it

public class Foo
{
 [Required(ErrorMessage="This field is required")]      
 public double? f1{ get; set; }
}

update:

to remove all validations on an input you can do

$("#f1").rules("remove");

for removing the range validation probably the following would work

$("#f1").rules("remove", "min max");

P.S this may not be the best practice...

2 Comments

I want to remove ONLY javascript validation and ONLY for range validator.
say if you disable the javascript validation with the Range validatior still in place and the user enters an out of range value the ModelState.IsValid will be false always...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.