How to Migrating From ASP.NET Web API 2 to MVC 6

How to Migrating From ASP.NET Web API 2 to MVC 6

CheapASPNETHostingReview.com | Best and cheap ASP.NET MVC 6 hosting. If you create a new MVC 6 project from the default starter template, it will contain the following code in the Startup class, under ConfigureServices method:

This pretty much explains it all – the Compatibility Shim is included in an external package, Microsoft.AspNet.Mvc.WebApiCompatShim and by default is switched off for new MVC projects. Once added and enabled, you can also have a look at the UseMvc method, under Configure. This is where central Web API routes can be defined:

Inheriting from ApiController

Since the base class for Web API controllers was not Controller but ApiController, the shim introduces a type of the same name into MVC 6.

While it is obviously not 100% identical to the ApiController from Web API, it contains the majority of public proeprties and methods that you might have gotten used to – the Request property, the User property or a bunch of IHttpActionResult helpers.

Returning HttpResponseMessage

The shim introduces the ability to work with HttpResponseMessage in MVC 6 projects. How is this achieved? First of all, the Microsoft.AspNet.WebApi.Client package is referenced, and that brings in the familiar types – HttpResponseMessage and HttpRequestMessage.

On top of that, an extra formatter is injected into your application – HttpResponseMessageOutputFormatter. This allows you to return HttpResponseMessage from your actions, just like you were used to doing in Web API projects!

How does it work under the hood? Remember, in Web API, returning an instance of HttpResponseMessage bypassed content negotiation and simply forwarded the instance all the way to the hosting layer, which was responsible to convert it to a response that was relevant for a given host.

In the case of MVC 6, the new formatter will grab your HttpResponseMessage and copy its headers and contents onto the Microsoft.AspNet.Http.HttpResponse which is the new abstraction for HTTP response in ASP.NET 5.

As a result such type of an action as the one shown below, is possible in MVC 6, and as a consequence it should be much simpler to migrate your Web API 2 projects.

Binding HttpRequestMessage

In Web API it was possible to bind HttpRequestMessage in your actions. For example this was easily doable:

The shim introduces an HttpRequestMessageModelBinder which allows the same thing to be done under MVC 6. As a result, if you relied on HttpRequestMessage binding in Web API, your code will migrate to MVC 6 fine.

How does it work? The shim will use an intermediary type, HttpRequestMessageFeature, to create an instance of HttpRequestMessage from the ASP.NET 5 HttpContext.

HttpRequestMessage extensions

Since it was very common in the Web API world to use HttpResponseMessage as an action return type, there was a need for a mechanism that allowed easy creation of its instances. This was typically achieved by using the extension methods on the HttpRequestMessage, as they would perform content negotiation for you.

HttpError

If you use/used the CreateErrorResponse method mentioned above, you will end up relying on the HttpError class which is another ghost of the Web API past rejuvenated by the compatibility shim.

HttpError was traditionally used by Web API to serve up error information to the client in a (kind of) standardized way. It contained properties such as ModelState, MessageDetail or StackTrace.

It was used by not just the CreateErrorResponse extension method but also by a bunch of IHttpActionResults – InvalidModelStateResult, ExceptionResult and BadRequestErrorMessageResult. As a result, HttpError is back to facilitate all of these types.

How to Create Nested WebGrid with Expand/Collapse in ASP.NET MVC 6

How to Create Nested WebGrid with Expand/Collapse in ASP.NET MVC 6

CheapASPNETHostingReview.com | Best and cheap ASP.NET MVC 6 hosting. In this post, I am explain How to Create Nested WebGrid with Expand/Collapse in ASP.NET MVC 6.
Steps :

aspnetmvclogo

Step – 1 : Create New Project.

  • Go to File > New > Project > Select asp.net MVC6 web application > Entry Application Name > Click OK > Select Internet Application > Select view engine Razor > OK

Step-2: Add a Database.

  • Go to Solution Explorer > Right Click on App_Data folder > Add > New item > Select SQL Server Database Under Data > Enter Database name > Add.

Step-3: Create table for fetch data.

  • Open Database > Right Click on Table > Add New Table > Add Columns > Save > Enter table name > OK.

In this example, I have used two tables as below

Step-4: Add Entity Data Model.

  • Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add.
  • A popup window will come (Entity Data Model Wizard) > Select Generate from database > Next >
  • Chose your data connection > select your database > next > Select tables > enter Model Namespace > Finish.

Step-5: Add a class for create a view model.

  • 1st : Add a folder.
  • Go to Solution Explorer > Right Click on the project > add > new folder.
  • 2nd : Add a class on that folder
  • Go to Solution Explorer > Right Click on that folder > Add > Class… > Enter Class name > Add.

Write the following code in this class

Step-6: Add a new Controller.

  • Go to Solution Explorer > Right Click on Controllers folder form Solution Explorer > Add > Controller > Enter Controller name > Select Templete “empty MVC Controller”> Add.

Step-7: Add new action into your controller for show nested data in a webgrid.

Here I have added “List” Action into “Order” Controller. Please write this following code

Step-8: Add view for the Action & design.

  • Right Click on Action Method (here right click on form action) > Add View… > Enter View Name > Select View Engine (Razor) > Check “Create a strong-typed view” > Select your model class > Add.

NOTE ” Please Rebuild solution before add view

Cheap ASP.NET MVC 6 Hosting only 1$/mo Click here

Save

Limited Edition !! Super Cheap ASP.NET MVC 6 Hosting only $1

Limited Edition !! Super Cheap ASP.NET MVC 6 Hosting only $1

CheapASPNETHostingReview.com | Choosing the best and cheap ASP.NET MVC 6 hosting service for your site isn’t always as easy as it should be – and if you’re not sure where to start it can seem a pretty daunting task. It doesn’t have to be. In this short guide, we’ll detail the four main types of hosting available, recommend a few of the best and cheap ASP.NET MVC 6 hosting providers in the industry and finish up by putting you on the path to learning the ins-and-outs of using ASP.NET MVC 6!

Limited Edition !! Super Cheap ASP.NET MVC 6 Hosting only $1

If you’re looking for the best ASP.NET MVC 6 hosting provider for your ASP.NET MVC 6-driven enterprise, choosing one of the providers listed in this guide will both set you off on the right foot and give you the freedom to customize your services at a later date (for example, upgrading servers specs etc as your business grows/expands) with relative ease. We’re not at all keen on web hosting companies that try to lock you into particular services with technical tricks! It will also connect you with the services of some of the very best, most-trustworthy ASP.NET MVC 6-web-hosting hands in the industry.

Choosing one of the Cheap ASP.NET MVC 6 hosting providers

Our winning recommendations for each type of ASP.NET MVC hosting – based on both our personal experience and the general consensus of the ASP.NET MVC community – with a brief summary of what makes each company special:

ASPHostPortal
$1.00
Host Intro
/mo
Host 1 Site
1 GB Disk Space
10 GB Bandwidth
0 SQL Server db
SQL Server 2008/2012/2014
0 MB SQL Server / db
0 MySQL db
0 MB MySQL /db
50 MB Email Space
Sign Up
ASPHostPortal
$5.00
Host One
/mo
Host Unlimited Sites
5 GB Disk Space
60 GB Bandwidth
2 SQL Server db
SQL Server 2008/2012/2014
200 MB SQL /db
3 MySQL db
200 MB MySQL /db
200 MB Email Space
Sign Up
ASPHostPortal
$9.00
Host Two
/mo
Host Unlimited Sites
15 GB Disk Space
150 GB Bandwidth
4 SQL Server db
SQL Server 2008/2012/2014
500 MB SQL / db
6 MySQL db
500 MB MySQL /db
500 MB Email Space
Sign Up
ASPHostPortal
$14.00
Host Three
/mo
Host Unlimited Sites
50 GB Disk Space
500 GB Bandwidth
6 SQL Server db
SQL Server 2008/2012/2014
1000 MB SQL / db
10 MySQL db
1000 MB MySQL /db
1000 MB Email Space
Sign Up

About ASPHostPortal.com

ASPHostPortal review is based on their industry reputation, web hosting features, performance, reliability, customer service and price, coming from our real hosting experience with them and the approximately 100 reviews from their real customers. ASPHostPortal offers a variety of cheap and reliable Windows ASP.NET Shared Hosting Plans with unlimited disk space for your website hosting needs.

ASPHostPortal revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24×7 access to their server and site configuration tools. Some other hosting providers manually execute configuration requests, which can take days. Plesk completes requests in seconds. It is included free with each hosting account. Renowned for its comprehensive functionality – beyond other hosting control panels – and ease of use, Plesk Control Panel is available only to ASPHostPortal’s customers.

ahp new

ASPHostPortal has a very brilliant reputation in the community. According to the statistics of the reviews we have received by now, almost all of ASPHostPortal customers are quite satisfied with this web host.So far there have been many reviews received from their real customers, the 98.0% of customers are highly happy with the overall service received, and there is nearly no complaint surprisingly.

ms_topASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for the ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET Core, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch.

Hosting Reliability

“Their servers never go down.” – when we surveyed on the reliability of ASPHostPortal. We have set up an uptime testing through Pingdom to monitor a ASP.NET site hosted on ASPHostPortal platform since July, 2013. So far, we haven’t detected any serious downtime which is longer than 10 minutes. ASPHostPortal always commits 99.9% hosting uptime in the real world. In the November 2014, there was no downtime and network interruption, and the testing site was 100% online.

ASPHostPortal Customer Service

The company provides 24/7 US-based technical support via email and live chat. Thus, customers can contact the experts immediately. What’s more, the company has promised that the first response time is in 2 minutes, which averages under 30 seconds in the real world. The support staffs of ASPHostPortal are all well-trained to resolve any technical problems effectively. Therefore, there is no need to worry about the capability of these people.

Besides, multiple FAQs are included in the section of Community Q&A, which provide people with the solutions for some common issues specifically. The Guides & Whitepapers offers multiple useful tutorials for site building.

ASPHostPortal is Highly Recommended for ASP.NET MVC 6 hosting

After reading so many outstanding points and positive reviews, the answer is very clear. ASPHostPortal is highly recommended for people who are looking for a multi-purpose, reliable, fast and trusted shared web host at an affordable rate. In case that you are planing to have your web presence or move out from your current horrible web host, ASPHostPortal is one of the best choices you won’t go wrong.

Simpan