1

I'm building a complex job application. And I want it to be a SPA. I'm using AngularJS with Asp.net MVC (not web API). Everything is working so far, but I realized that I can no longer take advantage of a lot of features that ASP.NET MVC provides. So far I know I have to write my own code for these features:

  1. all validation have to be on client side. I can't reuse some attributes I wrote in C#.

  2. [ValidateAntiForgeryToken] attribute no longer work.

  3. I can't use classes that generated by entity framework directly. It will give "circular reference" error for that.

I almost regret to take this approach. It's nice to have 2-way binding, but I have to write a lot of extra code that I could have avoided if I don't use angularJS. I can write multiple forms in one page and achieve the same result like shown here:

Multiple Forms in same page ASP.net MVC.

Can you tell what other MVC features I still have to write code for? when should I use angularJS and when should I use ASP.NET multiple forms on the same page?

Thanks

2
  • If you are using Angular, you really should be using WebAPI to simply return the data you need (in JSON) and then have the view templates render the view. Since you are using MVC to take care of rendering the views, you are defeating much of the benefits of Angular. If you want to do MVC and have 2-way data binding, I would go with Knockout instead of Angular for the client-side. Commented Apr 25, 2016 at 20:43
  • if I remember right, Knockout does not work with [ValidateAntiForgeryToken] either. you have to submit the form to make it work. Commented Apr 25, 2016 at 21:12

1 Answer 1

1

You can ease the pain of those listed points, but still, it might be better to decide what's better for you from the beginning - rendering views client-side (angular) or server-side (mvc).

Anyways, there are known solutions for some of the listed issues. Angular directive for MVC validation attributes: https://github.com/alisabzevari/ngval

For the [ValidationAntiForgeryToken] here is also a solution: https://julianjelfs.wordpress.com/category/mvc/

I have not understood the thing regarding multiple forms (I believe it's unrelated to angular), so skipped on this..

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

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.