MVC 4 website compatibile with Phonegap - asp.net-mvc

I'm developing an MVC website for mobile. The website should be compatible with Phonegap in the future, so I've done most of the client side logic using Web Api controllers and Ajax calls and my views are not linked to any Models. All my .cshtml files are now pure html/javascript codes.
But can I use MVC controllers to return empty views alone?
Will this work when I'm converting the code to phonegap?
because controllers usually return .cshtml files as views , but I will convert all cshtml to pure html in the future.

There is nothing to do with MVC in phonegap, phonegap uses Html/CSS for designing (front end) and JavaScript/JQuery/Ajax for logic (back-end).
Yes, you can return empty view but what about query and database related stuff, you have to use controller or model. This is all server-side stuff.
So answer is totally dependent on how is your Mobile App, for database connection you have to pass controller method's url in ajax call. For now, go ahead...

Related

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.
This method works but it feels more logical to do this via the initial asp.net-MVC Partial view load via #Model for example. 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.
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
If you use AngularJS,then it's not need 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.
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?
If there's a lot of client-side interaction, you will probably want to keep using Angular. If not, you might want to go back to using MVC since your use case doesn't really require Angular.

asp.net mvc routing with $routeProvider

Is there any sane way to use these?
What I want to have - is a single page with a nav-menu and <ng-view> below it.
And all the routing should be angular's responsibility.
But, I'd like to keep mvc goodness as well. I like neatly organized server-side controllers and razor pages.
I can't access .cshtml directly though, so how do I access my templates?
I don't want the main page and its content to be reloaded ever. It loads once and after that, all the navigation to other pages should be loading associated templates only.
How can I achieve that?
I can't find a single thorough example how to use them together.
Angular is used for single page web applications (SPAs).
ASP.NET MVC is used for server-side pages.
In ASP.NET MVC with Angular, your Index.cshtml or whatever your main view page is will contain all your JavaScripts and load your Angular app. You shouldn't ever navigate away from that page again. Angular's router just changes the URL (using a hash) and rebuilds the DOM based on the route.
They aren't supposed to "work together" for navigation. The only way they work together is if you create a REST API (or any API I suppose) with MVC and access it through Angular ($http, $resource, etc).
Checkout this project https://github.com/kazimanzurrashid/my-walletz-angular/blob/master/source/MyWalletz/Views/Home/Index.cshtml#L11 (shameless plug i am the owner) there is a helper method called IncludeClientView which inlines all the client side templates in the view. If you want to dynamically load the templates then create a controller and pass the template name from the client, then in the controller use partial view to return the template.
please install the AngularJS SPA Template from visual studio>> extensions and updates .

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.

Use an MVC Master Page in a WebForm page

I have an MVC application that I am creating that I have to integrate regular WebForms into the site. The WebForm pages will be using a ReportViewer control so I believe that won't work in a regular MVC view because ReportViewer uses ViewState, etc.
Is it possible for me to create a regular Web Form that uses an MVC View Master page? If so...is it possible to use the Html helper methods such as RenderPartial?
Is it possible for me to create a
regular Web Form that uses an MVC View
Master page?
I don't know for sure, but it might work, as long as it's just markup and doesn't use any MVC-specific features.
If so...is it possible to use the Html
helper methods such as RenderPartial?
Nope. If you use it this way, the Html property will not be set automatically, and I don't know of any way to hack it in.
We began a project in WebForms and realized partway through that MVC suits our purposes far better, so until we can finish migrating away from WebForms we have to maintain two separate versions of each of our "portal" elements (tabs, logout buttons, etc.). It's a pain, but it's doable.
Instead of using RenderPartial you could call a MVC controller with ajax from your webforms app and use the html it returns.
if (Request.IsAjaxRequest())
return View("someascx", model);

ASP.NET MVC for developing widget based portals

How suitable is ASP.NET MVC for developing anything like
http://www.google.com/ig?
I haven't seen or failed to find any examples yet. Does the MVC approach imply that the user interface is not supposed to look like that?
Check out http://aspspider.info/lakkakula/local.aspx, it is Web 2.0 Portal developed using Asp.Net MVC 1.0, Microsoft Ajax Client Templates and jQuery with drag and drop widget personalization much like google.com/ig.
MVC is quite suitable for such a UI. Your main controller can render with a list of the widgets the user has defined, or an ajax call to a method returning a JsonResult can be used... this can generate the wrappers client-side calling for each partial vie for the corresponding controls. I would think that MVC would simplify things quite a bit.
MVC + jQueryUI would be about all you'd need...
I guess a little bit more clarification, what exactly do you mean by "suitable"?
One method might be for each available "widgit" to be a controller, and then you can use jQuery (or whatever you want) to call the specified method and render. The page would then have a series of "lists" (which you can store in the DB) against the user and you can simply order those lists to display the relevant widgits in the correct order.
Obviously, that's a VERY large simplification....
See the tutorial Developing Web 2.0 Portal using ASP.NET MVC, Microsoft Ajax Client Templates and jQuery with drag and drop widget personalization.

Resources