1

Ref. this Microsoft's official video: http://www.asp.net/web-api/videos/getting-started/custom-validation

I downloaded the code and run it. It's fine.

Then, I remove all the client validation attributes(data-val-*) from the html file. It didn't work fine. I could not see the validation messages on the web page.

My question is how to regular the server side validation messages and how to display them as client-side validation.

1 Answer 1

1

Why would you delete the validation attributes? That's exactly what gets you the validation messages. To change the validation tests, you need to set the appropriate validation attributes on the model properties, e.g.,

[Required]
public string Genre { get; set; }

[Range(1, 100)]
[DataType(DataType.Currency)]
public decimal Price { get; set; }

[StringLength(5)]
public string Rating { get; set; }

As described in this post on ASP.NET MVC 4 Model Validation.

Sign up to request clarification or add additional context in comments.

1 Comment

I think I made some mistakes. You post is very helpful. Thanks.

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.