简体   繁体   English

为非单页应用程序创建带有angular.js的mvc-4应用程序的指南?

[英]Guideline to create a mvc-4 application with angular.js for non-single page application?

First of all i am confuse for my project whether it can use angular.js or not, although i have started using it and i created some customization module with this but when i started applying it for all project i got stuck on many things. 首先,尽管我已经开始使用它并创建了一些自定义模块,但是我对我的项目是否可以使用angular.js感到困惑,但是当我开始将其应用于所有项目时,我却陷入了很多麻烦。

My project is a order taking project and it has structure like this. 我的项目是一个接单项目,它具有这样的结构。 In the index page it has 3 panels. 在索引页面中,它具有3个面板。

left panle that draws all categories middle panel that draws all category specific productes and right panel that draws all the basket items with calculations. 左窗格用于绘制所有类别,中间窗格用于绘制所有类别特定的产品,右窗格用于绘制所有带有计算的购物篮项目。

On product click there also appears a model that draws all the customization. 在产品上单击时,还会出现一个绘制所有定制的模型。

I am using MVC-4. 我正在使用MVC-4。

Every thing on index that includes some layout is a partial view _leftpanl, _middlePnl, _rightPnl, _customziaion. 索引上包含某些布局的每件事都是局部视图_leftpanl,_middlePnl,_rightPnl,_customziaion。

My concern is. 我的担心是。 If i define the routes to the module i created how to fix on ng-view because per scope there will be one ng-view only. 如果我定义了到模块的路由,则我创建了如何在ng-view上进行修复的方法,因为每个示波器只有一个ng-view。 and my application load atleast 3 partial views to index page at the same time. 并且我的应用程序同时将至少3个局部视图加载到索引页面。 So how would i fix on ng-view. 那么我将如何修复ng-view。 Just gimme some guide lines that i should follow to create this kind of application with angular.js. 只是给我一些指导方针,我应该遵循这些指导方针来使用angular.js创建这种应用程序。 Or it is not possible with angular because i think it is not a single page application. 否则无法使用angular,因为我认为它不是单页应用程序。

Use the Angular-Breeze SPA template provided by the ASP.Net team http://www.asp.net/single-page-application/overview/templates/breezeangular-template 使用ASP.Net小组http://www.asp.net/single-page-application/overview/templates/breezeangular-template提供的Angular-Breeze SPA模板

Don't mix up the Razor view/partials with Angular. 不要将Razor视图/局部视图与Angular混淆。 Use ASP.Net MVC to manage only the REST interface and use AngularJS to embrace the presentation layer. 使用ASP.Net MVC仅管理REST接口,并使用AngularJS包含表示层。

Learn the Angular Routing and Templates to mimic your requirements. 了解Angular路由和模板以模仿您的要求。 https://egghead.io/lessons/angularjs-routeprovider-api https://egghead.io/lessons/angularjs-ng-view https://egghead.io/lessons/angularjs-routeprovider-api https://egghead.io/lessons/angularjs-ng-view

It seems you have a problem to define what you really need. 似乎您很难定义您真正需要的东西。

AngularJS primary purpose is to do some Single Page Application. AngularJS的主要目的是做一些单页应用程序。 Which is, code only in HTML/CSS/JS in the front-end, and reuse your abilities in the back-end to produce DATA only (REST-json is the most classic but you can choose whatever you want). 也就是说,仅在前端使用HTML / CSS / JS进行编码,并在后端重用您的功能以仅生成DATA(REST-json是最经典的,但是您可以选择任何内容)。

So if you use a tool outside its primary purpose, you have to do some compromises : Of course you can mix backend template with AngularJS, but in this case, you can forget the router and ng-view. 因此,如果您在工具的主要用途之外使用它,则必须做出一些妥协:当然,您可以将后端模板与AngularJS混合使用,但是在这种情况下,您可能会忘记路由器和ng-view。

Use AngularJS if you think you have some complex web interface. 如果您认为自己有一些复杂的Web界面,请使用AngularJS。 If it is only some static text, or even a few input forms here and there you don't necesseraly have to AngularJS, you can just use your classic server-side display rendering. 如果这里只是一些静态文本,甚至是一些输入形式,而您不必一定要使用AngularJS,则可以使用经典的服务器端显示渲染。

You could use ng-include to include each of your three partials into one view. 您可以使用ng-include将三个部分中的每一个都包含在一个视图中。 Then in each partial view you can specify the controller with ng-controller . 然后,在每个局部视图中,您都可以使用ng-controller指定控制器 For creating the modal popup I would probably use ui bootstrap's modal 为了创建模式弹出窗口,我可能会使用ui bootstrap的模式

Alternatively you could use ui-router to create multiple parallel views . 或者,您可以使用ui-router创建多个并行视图

I have following guidelines here which i hope will help you. 我在这里有以下指导原则,希望对您有所帮助。

  1. Do not mix Server Side MVC and Client Side MVC. 不要混合使用服务器端MVC和客户端MVC。 AngularJS is primarly meant to augment the HTML and browser capability. AngularJS主要是为了增强HTML和浏览器功能。 The two-way binding of angularjs is excellent and provides lots of dynamic behavior. angularjs的双向绑定非常出色,并提供了许多动态行为。 MVC4 scores best when we have to do lot of server side processing using the .Net platform capabilities. 当我们必须使用.Net平台功能进行大量服务器端处理时,MVC4得分最高。

  2. But as you spent some good effort on this project and the corresponding technologies, there is a way out. 但是,当您在该项目和相应的技术上花费了很多精力时,就有一条出路。 Convert all your Controlller Actions in MVC4 to produce JsonResult and when the angularjs needs data use that, eg in $http.get( . 在MVC4中转换所有Controlller动作以生成JsonResult,并在angularjs需要数据时使用它,例如在$ http.get(中。

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

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