0

I want to build a web app that have multiple pages. Each page must act like a SPA (interacting with users and create dynamic elements).

Is ASP.net MVC capable of handling front-side jobs as well or I should use frameworks like AngularJS?

  • 7
    ASP.NET MVC is a server-side technology. If you want client-side features, you should indeed use a client-side framework like angular. – TZHX Nov 7 '16 at 8:19
  • so as you say for my project I must mix them together to getting the job done . am I right? – Pingman98 Nov 7 '16 at 8:28
  • 1
    @Pingman98 SPAs are made using front-end frameworks. There's no way around it nor would I suggest one if I knew it. – Alternatex Nov 7 '16 at 8:46
  • @TZHX: It highly depens on the implemented features. I could create a simple SPA out of Ajax.ActionLink and Razor-generated views. – Flater Jan 18 at 7:21
0

It depends on the complexity of what you want to do on the app.

If its simple enough,it might be possible to implement it just using jquery and company, Or if its reasonably complicated you must go for a frontend framework that you/your team are proficient with/eager to learn along.

ASP.NET MVC is a backend framework so you can go only up to Views/Partial views level when it comes to front-end and there are no "ASP.NEt Controls" or any of that kind "Out of the box" to help you build the UI if that's what you are expecting.

If you really need controls maybe you should try third party stuff like Kendo UI

Hope it helps :)

  • 1
    jquery is a front end framework, so your answer isn't very helpful. – David Arno Nov 7 '16 at 11:01
  • @DavidArno Well, I just suggested it as an example, plus moderately complex SPAs definitely require a decent framework(which nowadays would be angular/<insert your fav F-end framework here>) to even be maintanable. – Naresh Kumar Nov 8 '16 at 12:07
  • @DavidArno: I wouldn't particularly call it a framework, it's a library. It mostly just does what you could also do in Javascript. Frameworks tend to be more architecturally inclined in regards to usage, such as angular requiring you to implement specific Angular concepts if you want a functional Angular app. JQuery requires no specific architectural approach and merely functions as a "simplified Javascript syntax". – Flater Jan 18 at 7:26
0

ASP.NET MVC renders the HTML at the server and returns that to the client.

When you want to communicate and build the UI in a SPA way then you CAN choose to use plain JavaScript to make callbacks to the server. This will however be very inproductive and I will not advice you to do this.

You can also use JQuery but that will be a tedious task too.

Best thing to do is use a client side framework.

I've created a few SPA's and looking how much is handled by the client side framework, I can't think of any reason not to use a client side framework.

0

Yes, if your application UI is not overly complex, you can use plain JavaScipt or Jquery on top of APS.NET MVC5 to create a multi-page SPA app (yes I know that sounds like a contradiction).

MVC 5 has helpers like Ajax.BeginForm that will handle the basics of the JavaScript work for you. It would be perfectly reasonable to have 1 controller per "SPA page", with each controller having a single Index method that returns a real View, and all the other methods returning JsonResult, and called via those Ajax.BeginForm's on the Index view. There will be a limit to the level of interaction you can achive with this simpler approach, but it might very well be enough to get you moving on your project. And don't be afraid in an "SPA" app to throw in a real page postback if you need it, maybe for handling exceptions/problems or doing a hard data reset on the page. There's no SPA-police who'll come arrest you for that!

IMHO everyone today has gone a bit off the deep-end with their desire to use the latest SPA frameworks, which are very necessary for complex apps, but overkill for simpler ones, if the developer in question does not already know the framework. Obviously if you take the time to learn Angular, then a simple Hello World SPA app is of course ridiculously easy, but obviously only if you've taken the time to learn it, which not every dev has!

0

Yes you can do that with a razor page. It would be a spa if you preventing the navigation.

But no good to use a razor page to creating spa. You have not to use anything for creating spa on asp.net mvc nor in asp.net core. You can use the document object for front-end directly but this will be very hard.

The best practics for kind of application is uses angular.js react.js vue.js knockout.js etc. VisualStudio also providing templates this type projects. Everything ready you can use :)

New contributor
dewelloper is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

Yes and no. It depends on what you mean by single page application.

If you mean "only data gets sent from the server", then using MVC5 is going to be mstly pointless, since other than the main page, you're not going to need any HTML generation. Subtracting the Razor views from MVC means you end up with WebAPI-like controllers (and nothing more); so you'd be better off just using WebAPI without MVC.
Note that on a technical level, it's perfectly fine to have both MVC and WebAPI in a single project. But you wouldn't really be leveraging any of the MVC features so there's little point to including it.

If you mean "no page reloads", but are okay with asynchronously loading HTML pages (partial views), then MVC5 can easily be used to this end. All you have to do is ensure that only your main page is a view, and everything else is a partial view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.