Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have finished a few MVC partial views which load their data using calls to a webapi Get method, to preload the data used by the angular controller.

This method works but it feels more logical to do this via the initial asp.net-MVC Partial view load via @Model for example. Rather than waiting for the page to load and angular to call the get method of my webservice i could have prepopulated the Model, but im not sure how this would pass the data to Angular using this method.

share|improve this question
    
What do you mean by partial views? JSON or rendered HTML? – Davin Tryon Aug 26 '13 at 22:32
    
asp.net razor partial views .cshtml – Tim Aug 26 '13 at 22:34
1  
Neither method you mention to get the data is necessarily wrong. It's really up to you how you want the application to load data. But since you're using Angular, I would think that loading the data in your controller and passing it to your partial view via @Model just defeats the purpose of using Angular. – Brett Aug 26 '13 at 23:33

3 Answers 3

I have had the same issue (if one call this an issue) and ended up doing binding the model to the partial view at the server side. The main rational for the decision was that the model was already available at the time at the server side and I was not building a Single Page Application.

Had I been developing a SPA, I would store the partials as templates at the client side, then grab the model via WebAPI and do the binding

share|improve this answer
    
This was my thinking also to bind the model at serverside,how would you populate the angular controller with the model at this point? i.e. load the data at serverside,but so that the model is still available to angular for future clientside postback etc. – Tim Aug 27 '13 at 6:55
1  
Hi Tim, One approach would be to serialize the model as a json object within the partial (@Html.Raw(Json.Encode(your_model))) and pass it to angular controller as a parameter via the scope. – Chintana Meegamarachchi Aug 27 '13 at 12:05

If you use AngularJS,then it's not need ASP.NET MVC. Just use web api for get data.I written a demo site for AngularJS+ASP.NET WEB API,hope to help you,this is the source code.

share|improve this answer

Does your web page have a lot of heavy client-side interaction or are you simply using Angular to initialize the data for your page on load?

If there's a lot of client-side interaction, you will probably want to keep using Angular. If not, you might want to go back to using MVC since your use case doesn't really require Angular.

share|improve this answer

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.