aspnet-mvc
  1. aspnet-mvc-aspnet-core-mvc-and-aspnet-mvc

ASP.NET Core MVC and ASP.NET MVC - (ASP.NET MVC)

ASP.NET MVC and ASP.NET Core MVC are frameworks for building web applications using the Microsoft .NET framework. In this tutorial, we'll discuss the differences between the two frameworks.

Syntax

The syntax for both frameworks is similar since they both use C# and the .NET framework. However, ASP.NET Core MVC has some changes in the middleware pipeline and in the startup class.

Example

Here's an example of a route configuration in ASP.NET MVC:

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 }
        );
    }
}

In ASP.NET Core MVC, the equivalent code looks like this:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseStaticFiles();

        app.UseRouting();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

As you can see, there are some differences in the middleware pipeline and the route configuration in ASP.NET Core MVC.

Explanation

ASP.NET Core MVC is a newer, cross-platform framework that is designed to be lightweight and modular. It was built from the ground up to support modern web development practices such as dependency injection and middleware.

ASP.NET MVC, on the other hand, is a more traditional framework that has been around for longer. It is built on top of the .NET framework and is designed to support the Model-View-Controller (MVC) pattern.

Use

ASP.NET Core MVC is a good choice for modern web development that requires cross-platform support. ASP.NET MVC is still a good choice for traditional web development on the .NET framework.

Important Points

Here are some important points to keep in mind when comparing ASP.NET Core MVC and ASP.NET MVC:

  • ASP.NET Core MVC is designed to be lightweight and modular, while ASP.NET MVC is more traditional and built on top of the .NET framework.
  • ASP.NET Core MVC supports cross-platform development, while ASP.NET MVC is for the .NET framework only.
  • ASP.NET Core MVC has a slightly different syntax and middleware pipeline than ASP.NET MVC.

Summary

In this tutorial, we discussed the differences between ASP.NET Core MVC and ASP.NET MVC. We covered syntax, examples, explanation, use, and important points when working with both frameworks. By understanding the differences between the two, you can make an informed decision on which framework to use for your project.

Published on: