简体   繁体   English

ASP.Net MVC赞成WebAPI加载初始Angular模型

[英]ASP.Net MVC verses WebAPI loading of initial Angular model

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. 我已经完成了一些MVC部分视图,这些视图使用对webapi Get方法的调用来加载其数据,以预加载角度控制器使用的数据。

This method works but it feels more logical to do this via the initial asp.net-MVC Partial view load via @Model for example. 此方法有效,但是通过例如通过@Model的初始asp.net-MVC Partial视图加载来执行此操作感觉更合乎逻辑。 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. 我本可以预先填充模型,而不是等待页面加载和angular调用我的Webservice的get方法,但是我不确定使用该方法如何将数据传递给Angular。

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 如果我一直在开发SPA,我会将部分内容存储为客户端的模板 ,然后通过WebAPI获取模型并进行绑定

If you use AngularJS,then it's not need ASP.NET MVC. 如果使用AngularJS,则不需要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 . 只需使用Web api即可获取数据。我为AngularJS + ASP.NET WEB API编写了一个演示站点,希望对您有所帮助,这是源代码

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? 您的网页是否有大量的客户端交互,还是您只是使用Angular来初始化加载页面的数据?

If there's a lot of client-side interaction, you will probably want to keep using Angular. 如果有很多客户端交互,您可能想要继续使用Angular。 If not, you might want to go back to using MVC since your use case doesn't really require Angular. 如果没有,您可能要重新使用MVC,因为您的用例实际上并不需要Angular。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM