ASP. NET MVC 4.0 project established in VS2017

Source: Internet
Author: User

The new project needs to run on the WIN2003, and do not want to use ASPX, had to use back to the ASP. MVC4.0, but in VS2017 there is no MVC4 template, the installation of the online download has not, had to put the previous MVC4 project took out to see a bit, See how the Blank project is set up with the following steps:

To create a blank Web project in 1.vs2017, remember to select the. NET 4.0 version of

2.NUGET package Search ASP. NET MVC, not the next 5.0 version, to the next 4.0 of that version


3. Manually set up the Controllers folder, inside the HomeController.cs class file, file content
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Net;
Using System.Web.Http;
Using SYSTEM.WEB.MVC;

Namespace Webapplication1.controllers
{
public class Homecontroller:controller
{
Public ActionResult Index () {
Viewbag.mes = "Niunan hahaha ...";
return View (); }
}
}

4. Create your own Views folder, inside the home folder, built-in index.cshtml file, file content:
@{
Layout = null;
}

<! DOCTYPE html>

<meta name= "viewport" content= "Width=device-width"/>
<title></title>
<body>
<div>
This is the MVC sample page
@ViewBag. Mes
</div>
</body>

5. Create a Web. config file under the Views folder, content:
<?xml version= "1.0"?>

<configuration>
<configSections>
<sectiongroup name= "System.web.webPages.razor" type= " System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, version=2.0.0.0, Culture =neutral, publickeytoken=31bf3856ad364e35 ">
<section name= "host" type= "System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, version=2.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35 "requirepermission=" false "/>
<section name= "pages" type= "System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, version=2.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35 "requirepermission=" False "/>
</sectionGroup>
</configSections>

<system.web.webPages.razor>
<pages pagebasetype= "System.Web.Mvc.WebViewPage" >
<namespaces>
<add namespace= "SYSTEM.WEB.MVC"/>
<add namespace= "System.Web.Mvc.Ajax"/>
<add namespace= "System.Web.Mvc.Html"/>
<add namespace= "System.Web.Routing"/>
</namespaces>
</pages>
</system.web.webPages.razor>

<appSettings>
<!--<add key= "webpages:enabled" value= "false"/>-->
<add key= "webpages:version" value= "2.0.0.0"/>
</appSettings>

<system.web>
<add path= "*" verb= "*" type= "System.Web.HttpNotFoundHandler"/>

<!--
Enabling request validation in view pages would cause validation to occur
After the input have already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the Validateinputattribute to a
Controller or action.
-
<pages
Validaterequest= "false"
Pageparserfiltertype= "System.Web.Mvc.ViewTypeParserFilter, SYSTEM.WEB.MVC, version=4.0.0.0, Culture=neutral, Publickeytoken=31bf3856ad364e35 "
Pagebasetype= "System.Web.Mvc.ViewPage, SYSTEM.WEB.MVC, version=4.0.0.0, Culture=neutral, publickeytoken= 31bf3856ad364e35 "
Usercontrolbasetype= "System.Web.Mvc.ViewUserControl, SYSTEM.WEB.MVC, version=4.0.0.0, Culture=neutral, Publickeytoken=31bf3856ad364e35 ">
<controls>
<add assembly= "SYSTEM.WEB.MVC, version=4.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35" namespace= " SYSTEM.WEB.MVC "tagprefix=" MVC "/>
</controls>
</pages>
</system.web>

<system.webServer>
<validation validateintegratedmodeconfiguration= "false"/>

<remove name= "Blockviewhandler"/>
<add name= "Blockviewhandler" path= "*" verb= "*" precondition= "Integratedmode" type= " System.Web.HttpNotFoundHandler "/>
</system.webServer>
</configuration>
Feel the same as the default MVC5 built, just change the version number from 5.0.0.0 to 4.0.0.0 ...

6. Establish the App_start directory, which establishes the FilterConfig.cs file, content:
Using System.Web;
Using SYSTEM.WEB.MVC;

Namespace WebApplication1
{
public class Filterconfig
{
public static void Registerglobalfilters (Globalfiltercollection filters)
{
Filters. ADD (New Handleerrorattribute ());
}
}
}
It doesn't matter if I don't have this file.


Create RouteConfig.cs file in 7.app_start directory, content:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using System.Web.Routing;

Namespace WebApplication1
{
public class Routeconfig
{
public static void RegisterRoutes (RouteCollection routes)
{
Routes. Ignoreroute ("{resource}.axd/{*pathinfo}");

Routes. MapRoute (
Name: "Default",
URL: "{controller}/{action}/{id}",
defaults:new {controller = "Home", action = "Index", id = urlparameter.optional}
);
}
}
}
To use MVC, this file is the most important word, using the MVC route to create

8. Build the Global.asax file under the project root and register the two classes set up in Application_Start, the main content:
protected void Application_Start (object sender, EventArgs e)
{
Arearegistration.registerallareas ();
Filterconfig.registerglobalfilters (globalfilters.filters);
Routeconfig.registerroutes (routetable.routes);
}

9. Run the project, you can see the interface came out, but it seems that the smart tips in cshtml is not, do not know how to do, First of all!!!

ASP. NET MVC 4.0 project established in VS2017

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.