Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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 Jul 9 '13 at 5:56
    
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 Jul 9 '13 at 6:04
    
Yes you have to load everything on the index page . – Ajay Beniwal Jul 9 '13 at 6:14
up vote 2 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 Jul 9 '13 at 15:47

I blogged about how to convert VS's built-in SPA template to be an AngularJS project and in that post, I demonstrate one approach toward defining your routing and creating your partials. I think it will help someone. It would have helped me a few months ago. ;-)

http://blog.danielmcfarland.net/create-angularjs-spa-with-asp-net/

share|improve this answer
    
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Paritosh Aug 9 at 6:22

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.