Using Sencha's ExtJS MVC with ASP.NET MVC - asp.net-mvc

I wanted to ask if anyone has tried using combination of Sencha's ExtJS 4 (using MVC approach) with ASP.NET MVC (using view models)?
I have existing ASP.NET MVC 3 app that uses view models and my question is how would this "fit" into Sencha's MVC approach...Would ASP.NET MVC "view model" become ExtJS "model" and then I would define yet another "view model" for ExtJS....Seems a lot of "translating"...
What would be the best approach?
And yes, I am aware of projects that integrate ASP.NET MVC with ExtJS using Ext.Direct, but my question is strictly relating to MVC paradigm on "both" sides (ASP.NET and Sencha ExtJS)
Thanks
Z...

Our approach currently is a what could be described as MVCCM or MVC-CM.
In ExtJs you have the view as panels and boxes etc, a store with a model makes a model and you need some logic to make these components work together which would be the controller.
This ExtJs frontend is situated in a MVC3 project and exposes controller methods that typically returns Json data which it gets from the model back end which is typically made up of entities.
There is no programmatic link between the entities on the server side and the models defined in the stores client side. One could generated the stores from entities, but we have not looked into this yet.
The view in the Microsoft MVC3 framework is just a page that returns some div tags which ExtJS can render stuff into.

While I've not done this with ExtJS, I really don't think there's any conflict. I'm assuming a lot here, I know, but if ExtJS works with JSON and you've got ASP.NET MVC actions that emit JSON, it's really more of a philosophic difference than a technical one.
One difference from a normal MVC app would be that your ASP.NET MVC app might not have any views, since the views would be handled entirely by ExtJS.
From the server side, ASP.NET MVC really doesn't care - it's getting a request that gets mapped to a controller and action, processing the request and returning some result. Whether that result is HTML, JSON, XML or whatever, ASP.NET doesn't care at all.

Related

Net5 razor pages vs mvc

I am new to net5 framework and have some questions regarding the structure of the project.
When we create a new project it will only create the razor pages. I am learning that we can achieve things with these razor pages.
Meanwhile, I have looked into some open source net5 projects on GitHub and see that they are also using MVC.
So, my question is why do we need MVC then? If everything is achieved using razor pages then what is the need for MVC?
If we need MVC then should we use razor pages with them too?
I have done the identity work with razor pages using scaffolding. What would happen now if I add MVC to my project. How will I manage the routes and page redirection from razor pages to MVC and vice versa?
Please help me with this so I can clear my concepts on this.
I will be really thankful to those who explain the scenario to me.
Thanks
First, .NET 5 is out of support. You should target .NET 6 instead.
Razor Pages represents a simpler way to generate HTML on the server compared to MVC. It is recommended for all new web applications that rely on server-side HTML generation going forward. MVC is still available for existing apps. It is also probably easier to migrate older MVC 5 (.NET Framework) apps to ASP.NET Core MVC when porting to .NET Core.
Razor Pages is built on top of the MVC framework and depends on a lot of the features of MVC such as model binding, action results and so on.
If you are using Razor Pages, there is no compelling reason to also use MVC in the same project, although you can. If you do, then you need to register controller endpoints:
app.MapControllers();
You might need to add controllers to your project if you want to create HTTP service APIs, although you can use the minimal API feature that was added to .NET 6 instead:
https://www.mikesdotnetting.com/article/358/using-minimal-apis-in-asp-net-core-razor-pages
Razor Pages can make coding page-focused scenarios easier and more
productive than using controllers and views.
https://learn.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-6.0&tabs=visual-studio
As another difference, in MVC, you usually create separate class for ViewModel. As I understand, in Razor Page, you don't need a separate class and you just add more properties in the same page and those properties will be part of your model which make things easier.

ASP.NET MVC without database INSERTS

I used asp.net web forms before and currently thinking to switch to MVC, the issue is, my current project is against a 'real time database' - PI from OSISoft - where I don't need CRUD operations at all, its a view only application; is the MVC model still applicable here or what?
Sorry for the newbie question.
ASP.NET MVC and Web Forms are web application frameworks. They don't define any constraints on data access. With a little refactoring you should be able to use same data access code (C# or VB) in an MVC application.
Funny, I just created a dashboard for a PI server. Used ASP.Net MVC and Web API to surface the information, it worked a treat.
Note MVC doesn't actually have anything to do with data persistence. It is simply a well-conceived UI design pattern.

using ASP.NET MVC and EXT JS together

I'd like to use for my next project Ext js and ASP.NET MVC.
I'm wondering what would be the best way of using this two framework together. So far I did some project using ASP.NET MVC, where every action method returned a view and reloaded the page. The Ext js mvc application uses a single page approach.
As I'm pretty new to ext js so I'm wondering if someone could share some experiences of building real world application using this two frameworks.
You can use extjs as you think is better for you. You can use its components as simple widgets or create a full javascript (extjs) client. However, which are the real requirements? a single page client or a traditional client?
In our current project we started using ASP.Net MVC Framework with extjs widgets, it was ok for a while but the customer wanted more and more sophisticated UI and a better user experince (among other thing) then, we changed the app, we left MVC models and controllers (views were removed) and we created a full javascript client with extjs 4.1.
After that we realized we were using an ASP M_C framework (with no views) and that was a nonsense so, we took the ASP MVC project away and replaced it by a WCF Rest service (it also could be done with an ASP.Net Web Api).
We feel proud of our decision and the resulting design. If you can, if you know extjs (learning it is rather hard) and javascript and, if you have support to your decision then, keep your application splitted in two:
a server-side service/api and,
a full javascript application.
Good luck!
I'm not sure I'd agree with the answer by #lontivero, I'm currently working on a project using ASP.NET MVC as the backend and ExtJS as the front.
You do, as pointed out, loose the V from the ASP.NET MVC stack and you end up needing to duplicate you C# view models in you ExtJS Models on the client side but I've found using MVC as a backend (effectively as a rest based collection of Json end points) absolutely fine.
You can utilise the model binding, model validation in MVC whilst leveraging the full client side js app in Ext.
I'm curious as to the points you didn't get on with using this structure (I'm not saying it's perfect, but it does seem to work)
We used Ext.NET (versions 0.x-1.x) in our previous projects. Even after a comprehensive effort to upgrade our projects to the (now current) version, we had to drop Ext.Net 2.x out.
If it fits you, it can help.
The main problems with Ext.Net were (several) incompatibilities with ASP.NET and a lack of trust. They used to keep their schedule, it's far from it for last 2 years or so. And they are behind ExtJS.

Using same Model for MVVM and MVC

I have a query regarding MVVM and MVC. I am developing an Desktop Client and Web application. I intend to use WPF (and MVVM) to develop desktop client and ASP.Net MVC for web app.
I have never used ASP.Net MVC before although I have never truly liked Web Forms (except some features like Master Page, output Cache etc.) and I mostly use AJAX (jQuery), and handlers to populate HTML and processing inputs (I think I was close to MVC after reading about the pattern but in a different way).
Now these applications will mostly have same inputs, reports, and database. I am planning to create Model that can be re-used in MVVM and MVC both. But after reading various articles on these pattern, and analysis of ASP.Net MVC Code, I doubt that it could be done. In MVVM, View never knows Model while in MVC, Controller shares Model with View. Also, in ASP.Net MVC, a View (ASPX file) is derived from System.Web.Mvc.ViewPage and the labels/captions are populated from Model itself.
Is there a way I can use same Model for both applications?
Thank you.
Ritesh
In MVVM, View never knows Model while in MVC, Controller shares Model with View.
Not quite right. In MVVM the view is bound to a view model. Exactly the same as in ASP.NET MVC. In ASP.NET MVC a Controller doesn't share a Model with the View. It shares a View Model. It talks to the Model and then builds a View Model that is passed to the View.
Contrary to MVC in MVVM the View could talk to the Model but this happens indirectly throughout the View Model, so neither the View nor the Model know about each other's existence.
So you could perfectly fine have the same Models in both your Desktop client application and in your web application. The only difference will be the view models.

Incorporating MVC functionality in an existing ASP.net project

We have an intranet system developed using asp.net webforms. We are kind of planning to partly incorporate mvc and such a scenario is as follows,
We would like to generate html documents using mvc (using razor view engine) where the inputs are going to come from a normal asp.net webform (from a form button click or so)
Some pointers or references to tutorials on running these 2 scenarios side by side would help a lot.
ASP.Net MVC and WebForms postbacks don't mix; the only way to do this would be to use <iframe>s (which is not a good idea).
I am not sure about your described implementation... however, you could start by re-writing some of your aspx pages using MVC views and just get all the existing code behind into a controller to minimize the creation of new code. You could do this one page at a time until all of your pages are MVC views. Good luck.

Resources