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.
-
Let's see what you've tried and we can help show you where you went wrongTom– Tom2014-04-03 13:50:30 +00:00Commented 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.abstractOverride– abstractOverride2014-04-03 14:05:14 +00:00Commented Apr 3, 2014 at 14:05
-
Did you find any concrete samples? we are pursuing the same avenue now but with MVC5...Vadim K.– Vadim K.2014-05-16 17:48:01 +00:00Commented 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. :)abstractOverride– abstractOverride2014-05-19 03:54:12 +00:00Commented May 19, 2014 at 3:54
Add a comment
|
2 Answers
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.
3 Comments
abstractOverride
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.
Beyers
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.
abstractOverride
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.
see: https://github.com/alisabzevari/ngval
<input type="text" name="username" ng-model="user.name" @Html.NgValFor(u => u.RequiredProperty) />