Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When using angularjs, I am serving up the home index page via ASP.NET MVC4. But I want this to be a SPA. For angularjs routing, does that mean I abandon partial server side views a la MVC and just work with html pages as my angularjs 'partial' views?

Anyone done this, and if so what approach did you take? Simple html pages with angularjs or some other solution?

share|improve this question
1  
During the first load you should serve the index page from MVC after that you should just rely on html page of angular app .Just server the static html pages without making use of asp.net infrastructure. – Ajay beniwal 18 hours ago
Ok.. that's what I was thinking... one drawback though is the nice bundles for scripts and css that might be specific to the partial html view... I suppose that also makes sense to load those things in the index page as well since it is a SPA... – Nicros 17 hours ago
Yes you have to load everything on the index page . – Ajay beniwal 17 hours ago

2 Answers

up vote 1 down vote accepted

In the SPA model, you only serve the main view which will contain all the angular code to perform the dynamic page updates. Your server side actions could only return JSON data to the client and consumed by AJAX calls from angular. Partial server side views are indeed no longer necessary.

share|improve this answer

What Darin said is true.

Just to add to it, I'd suggest pairing Web Api with angularjs instead of standard MVC because it's a better fit. You don't need mvc partials (because they're server side partials and angularjs is client based).

So all your server stuff which would be json etc will be handled through ApiController actions. you could have your models etc still there like normal. But for your MVC views, it'll be just the one. All your angularjs SPA routes will be handled within angular.

share|improve this answer
This is in fact exactly what I have :) web api is handling all the data to and from a SQL server, and I'm just serving up the index.cshtml page- angularjs and routing with static html will handle the rest. – Nicros 8 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.