I want to build responsive SPA web application. I followed old paradigms before and the way it is supposed to be done nowadays is not very familiar to me, so sorry if my question seems unadequate.
Now I'm trying to understand the motivation behind this MVC 5 SPA template: why would I need to use MVC and Web API in one application?
My app will not act as a service. I can simply return JSON from my action methods. If in my case it is absolutely not neccessary, what factors could change the situation in favor of using both WebAPI and MVC at the same time?
You don't have to but it is useful.
I'm usually using MVC for
generating initial html file for my SPA through index.cshtml
(bundles + some customization of initial html code)
generating dynamic JavaScript code (usually for something like configuration angular modules)
Web API or OData kicks in aferwards providing endpoints for your favourite SPA framework (angular / knockout etc.) returning json or even xml if you need.
Related
I have worked in ASP.NET CORE MVC, before.
What are all the advantages in using ReactJS over ASP.NET CORE?
Would not that additional library & its components, slow down the page
load, comparing plain Razor Views?
I tried web search, I am unable to get proper answers.
If you have independent apps in PC,Phones tablet,etc,you could just use React and core web api which is front-end and back-end separation.
By using Angular/React with api in server side:
1.You eliminate process of generating HTML in server side and you save CPU.
2.API produces small payload (json) and Razor (html) would be much larger in size, constant full page reloads and postback round trip. so API and SPA save bandwidth.
3.API and SPA could have different versioning, scaling and deployment scenarios.
4.By using API you can support mobile app too and if you start by Razor you may need api in future.
Below are some opinions on using Angular/React or razor:
1.Razor supports mobile,and both are optimized and fast in their own way. Razor optimizes code by not using a tree like MVC does. React is client side so it doesn't really use a tree, but also optimizes data in the HTML to an extent.
2.Angular (or React) is far superior in terms of performance.The model-binding aspects of Angular is a gigantic advantage of server-side rendering. Using Razor(or server side rendering in general) does, however, lend itself to better overall integrity as far as data goes and it makes for a better transition of data from front-end to back-end.
See ASP.NET Core 2.0 Razor vs Angular/React/etc
What are all the advantages in using ReactJS over ASP.NET CORE?
ReactJS is high performance and rapid development client side framework, you can use it throw asp.net core or any other server side framework to handle client side operations.
Would not that additional library & its components, slow down the page
load, comparing plain Razor Views?
ReactJS designed to be a single page application, and this kind of apps is more faster than multiple page applications, also ReactJS processing the DOM in different and smarter way.
If you want to use ReactJS in asp.net core you must keep in mind that asp.net core is the api part just to return the data (json or xml) or to receive your ajax request to post data.
All clients side parts will handled by ReactJS, no razor views, you can have only one to reference your reacts application or simply you can reference it using plain html page.
I've explored the ASP.net web API framework and MVC 4. I understand the point of using web API that only return data then in client side we use javascript, ajax to handle all actions via HTTP verbs. On the other hand, MVC controller can return data and view we can handle event via [HttpPost] in controller.
I saw some people they make 2 projects in a solution: one is Web API in MVC 4 and the other is MVC 4 Internet Application. Is it a good idea? I didnt see the relation between two kind of projects. Can anyone explain me the how two project can communicate with each other, and what is the advantage and disadvantage of that way?
Note: in this solution he/she still uses Httppost to handle event and use MVC controller return view with Model binding.
Well I guess this is going to be a pragmatic conversation...
For starters, it seems like the Asp.net WebApi and Asp.net MVC are going to be aligned in Asp.Net V-Next, so there is going to be One base controller class that will return what ever datatype you wish (ActionResult, Json etc).
And from the recent years experience I think the trend is to have a WebApi that exposes data and a portal(client) that is just a JS web application with no C# code that just calls the Api from the browser and does what it needs to do.
So that way we basically save one hup to the server(the MVC server) and we can directly call the API from the browser.
However some people would still argue about load balancing, scaling, caching etc that you could have if you keep the MVC tier there but still all those things could be done in the WebApi and JS application too...
So long story short, I think if you want to move with the trend I think you should go with a RESTful API and have your client to call it from the browser directly with JavaScript...
I am currently starting a massive web app project, and one of the requirements is that down the line I may be required to allow an iOS and Android app to interface with my application, I figured the best solution was to create a RESTful API and have the web application interface with it. However, my coworker who does front end development is unfamiliar with using a javascript framework such as backbone.js (more of a library I know), ember.js or angular.js. Since we're using asp.net I figured that the I could handle authentication and routing using asp.net MVC, delivering seperate views depending on the route, and he can handle the data manipulation only, However, I can't seem to figure out how to seperate routing from the javascript framework, I've looked into ember.js and backbone and both of them seem to require routing to be handled on their end for it to really work.
Does anyone have any idea how to implement data manipulation without the need for routing?
What you are describing is generally called API oriented architecture, meaning you have a RESTful service on a back-end and rich client-side application on front end.
The point is, it basically does not matter what technology you pick up on server. It could be anything: ASP.NET MVC, Web API, Express.js or Django. As soon as it's really RESTful and pure. By purity I mean, it deals only with data, no serving of HTML or something.
Server just specify the interface you work with data,
GET /invoices // get all invoices
GET /invoices/:id // get invoice by id
POST /invoices // post new invoice
If you confident with .NET, WebAPI is probably good choice. Typically you would prefer JSON output, WebAPI could handle content negotiation for you.
Now, the client job is to consume the API data and dynamically create HTML in browser. A lot of options now: Backbone.js, Angular.js etc.
Please be aware: client side routing and server side routing are completely different things.
Server side routing: routes particular HTTP request to particular controllers action (or any function).
Client side routing: detects the URL change and triggers corresponding JavaScript function to handle change. Client side routing is vital for SPA (single page applications). You can find a bit more information on SPA on that blog post.
Have a look at KnockoutJS, which would allow you to use ASP.NET MVC for routing or another JavaScript library like sammy.js (just for routing) or Durandal (for routing and navigation).
Note: Durandal version 1 used sammy.js internally, but version 2 has a custom routing engine and no longer uses sammy.js.
Im currently starting a new WebProject. The plan is to generate the entire frontend via extjs and communicate with a C# .Net Backend (via ExtDirect !? )...
My problem is that i dont really know what VisualStudio Project Type i should use..
The backend should only handle the requests from the Ext JS (and communicate with an other EntityFramework Projekt though thats not a problem)... Are there any tutorials around? I didnt find something like that. I am not sure if i have to use an ASP Web Form Project because i didnt planned to use any ASP controls or something like that. Like i said i want the frontend to be generated by EXT JS only.
Please help. Im glad about any input :)
I've built a project with ASP.Net MVC and extjs as the front end. You could also use something like a WCF service to handle your server side calls but the ASP.Net MVC framework works fine as well.
I used an Ajax proxy in my stores that call my ASP.Net controllers which then call the database and I return the result back as json.
I used this project TraXPLORER = ExtJS 4 MVC + ASP.NET MVC 3 + CRUD + REST to help me get started.
You also may want to check out Ext.Net as it's a wrapper for the extjs library for .Net apps.
I've been doing some digging in the web but all i find is either incomplete guides to do it by yourself or guides for the first version of MVC.
Is there any framework for getting a RESTful API or not?
And if no, is there anyway to add a global solution for all models (extending the model or routing of MVC it self), because what i've read involves adding the REST logic to each model/ controller of the application (Which don't look like a good solution to adopt REST)
WCF Web API for MVC3
Add WebAPI support to MVC3 application
Both of these should give you an idea of what's involved.
Are you able to start using MVC4?