0

How can I hook my asp.net mvc model validation to angular js? for example I will use ASP.net MVC 4 as WebApi, then for my front.end I will use AngularJS.

4
  • Let's see what you've tried and we can help show you where you went wrong Commented Apr 3, 2014 at 13:50
  • for example I have Model Person which has a property of FirstName and LastName and this are required field. (Im new in angularJS) in angularJS side, how does validation hook in angularJS without manually rewrite the validation. Commented Apr 3, 2014 at 14:05
  • Did you find any concrete samples? we are pursuing the same avenue now but with MVC5... Commented May 16, 2014 at 17:48
  • @Jk_xp none at the moment what we did is just a duplication of code 1 for client side and other 1 for server side. :) Commented May 19, 2014 at 3:54

2 Answers 2

1

You can't use MVC's build-in client side validation in Angular. You will need to use Angular's own validation mechanisms. The up side of this is that you can rely purely on ASP.NET Web Api and not use MVC at all.

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

3 Comments

thanks, so what you saying is there's duplication of code. And if I have business logic validation this would be invoke upon post? thanks.
Yes, you will have Angular client side validation for stuff like required, min/max length etc. And on server side you still do your full validation using model validation or whatever server-side validation framework you are using. It's not as smoothly integrated as MVC client validation, but very flexible and easy to use.
Thanks Beyers, hope I can find if there is. a open source, that can integrate ASP.NET MVC and angularJS. And I think it is possible to have that soon.
0

see: https://github.com/alisabzevari/ngval

<input type="text" name="username" ng-model="user.name" @Html.NgValFor(u => u.RequiredProperty) />

Comments

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.