ASP MVC 5 WebAPI vs Ajax.ActionLink - asp.net-web-api

I am having some difficulties understanding the difference between ASP.Net MVC WebAPI Controllers (System.Web.Http.ApiController) and #Ajax.ActionLink (PartialViews).
As my knowledge of MVC 5 and razor is not very profound I wonder why I should use ApiController (except for the obvious reason, when I have an external application that requests data from my webapi).
My requirement is to easily do ajax AND leverage the built-in mechanisms like validation and such.
At this time I use WebApi and jQuery - which works pretty well, but on the other hand i have to do all the exception handling (ie. validation) manually again.
Any advice?

Related

Does Kendo include a MVC framework, data handlers, etc?

We are trying different JavaScript libraries. The one I just completed is Sencho Ext JS and it is pretty much everything. It has controls, a MVC framework, data handlers, etc. I'm diving into Kendo and it looks like it is mostly UI controls, working with JQuery.
Is this correct? And if so, for the MVC framework & data binding, is there any libraries that work best with Kendo?
Kendo UI includes
UI Widgets
MVVM Framework (client-side)
SPA Framework
It also has an ASP.NET MVC Server Wrappers available as an optional package (that is also an additional cost). This provides a .NET library that can be used to add server-side data paging, filtering, and sorting to your MVC controller actions. This works best if you are using Linq queries (or Entity Framework). It also provides a set of Razor functions that can generate the JavaScript to initialize Kendo UI widgets.
For an example of the MVC Server Wrappers in use, have a look at the Sales Hub sample project.
Sales Hub live site
Sales Hub source code (GitHub)
Though, to be honest, I recommend just using JavaScript to init the widgets instead of the Razor helper functions. However the DataSourceRequest and DataSourceResponse classes provided by the MVC server wrappers are very useful.

Execution sequence of MVC Routes and HTTP Modules

Does the handler for MVC Routes trump the HttpModules defined in web.config?
I have an asp.net app that consists of legacy webforms code and MVC code. I want to prove to myself that MVC is taking precedence for handling requests over a custom HttpModule the project uses, which can also handle requests.
IIRC the MVC routing is done in the HTTP module which launches MVC. So MVC will "win" as long as it's http module is added before your custom one.
I was almost correct. MVC implements a UrlRoutingHandler which means that it will direct the request before any module is invoked.
Source code:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/5b4f63fa0b89#src%2fSystem.Web.Mvc%2fMvcHttpHandler.cs

CRUD operations using asp.net Icontroller Versus using asp.net ApiController inside my asp.net MVC

If I need to build a web application that implement functionalities related to managing an Medical hospital institution. That application include functionalities to add, update, delete, search and retrieve patients, medical visits, etc.
So I am confused on which approach to follow inside my ASP.NET MVC web application, either to have my controller classes inside my asp.net MVC.
Derived from IController to perform the CRUD operation
OR
Derived from ApiController to perform the CRUD operations
SECOND question is there an approach that is taking over the other, and what are the advantages/disadvantages of each approach over the other?
You can absolutely use both. Nothing stops you to use good old Controller to do CRUD in JSON and MVC is capable of doing it. However, you do not get all the nice features of Web API such as content negotiation, message handlers, media type formatters, etc.
If you do not need any of Web API specific features, then use MVC. But on the long run, Web API will be a better investment as I believe adoption will rocket soon.
If you are going to generate classical HTML pages from your controllers, use the MVC ones. If what you want to return to a client is some kind of serialized data (XML, JSON, ...), use Web API controllers since these make it easier, regarding e.g. content negotiation.
See also Getting started with Web API

Migrating a legacy Webforms application to asp.net mvc?

does anyone have good links or tips on best practices concerning migrating from ASP.NET Webforms to ASP.NET MVC?
We have a large webforms application that we would like to piece by piece migrate to MVC. Here is our current setup.
Two big Webforms project (VB)
Multiple class libraries and services (C# and VB.Net)
Subsonic 2.2 Data access layer
SQL Server 2008 DB
We are considering the following:
Keep the classic webforms project running as is for now while developing.
Create new MVC project based on MVC 3 with Razor view engine
Use Nhibernate (Repository pattern) DAL
Convert/build the existing functionality module by module in the MVC project
Replace some functionality in the old webforms project with new MVC modules if possible. Integrate via eg. Iframes.
In time the new MVC app will replace the old webforms project entirely.
We would like to keep the DB as is so we also need a tool to create the Model based on the DB.
Is this a possible solution?
WebForms applications use server-side session a lot because most of the server controls use it internally. You will not be able to use any of the server controls that you used in WebForms in MVC3 (atleast without some tinkering).
MVC3 promotes the use of restful architecture, where any state is maintained in html or url or cookies, and these are reasons why I think you should revisit the decision to convert to MVC3. Do so only if it will give you a huge advantage, because I suspect you will be reinventing ground up your existing app - I suspect there will be an equal amount of effort migrating it as to while developing it new.
Again there is nothing preventing you from creating an "area" or a "region" of MVC in your webforms app, if your goal is to use MVC for future development.
If you still want to move to MVC3, take a look here
It is ok solution. Also for NHibernate you can use MyGeneration with NH plugin to generate models on top of existing DB. And it is also possible to host WebForms and MVC together in one web app. Just finished quite the same task. But used EF for DAL.

ASP.NET WebForms vs MVC [after VS2010/.NET 4.0 announcement]

Two of the biggest advantages of MVC over webforms were non-existent viewstate and URL routing. VS2010 and .NET 4.0 incorporates built-in URL routing for Webforms as well as better control for viewstate.
I advocate use of MVC for extranet sites due to the MVC design pattern and its general lightweight nature but in light of this new announcement has Webforms closed the gap? Why would you still pick MVC over Webforms?
Thanks
You're forgetting about 2 main advantages of MVC: better control over generated HTML and better support for test-driven development.
I'd say that normally implementing a site using ASP.NET WebForms would require less effort that implementing exactly the same with MVC.
MVC gives you more control, but it also requires more expertise and effort.

Resources