1

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.

3
  • What do you mean by partial views? JSON or rendered HTML? Commented Aug 26, 2013 at 22:32
  • asp.net razor partial views .cshtml Commented Aug 26, 2013 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. Commented Aug 26, 2013 at 23:33

3 Answers 3

1

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

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

2 Comments

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.
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.
0

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.

Comments

0

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.

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.