top of page

NET MVC vs NET Core


I've been asked a few times if a new developer should focus on learning .NET MVC or .NET Core. The simple answer is: both.


.NET Core is a framework, whereas MVC is a code architecture pattern. You can create a project / solution in Core and use the MVC pattern for your code. However, if you choose to begin a project with a base MVC project file, you cannot use the Core framework for it.


MVC is Model View Controller pattern.


A great resource to learn more from is Microsoft. The main page that begins the deep dive is https://dotnet.microsoft.com/apps/aspnet/mvc


A few overall takeaways from the Microsoft resource:


A data Model example:

public class Person
{
   public int PersonId {get;set;}

   [Required]
   [MinLength(2)]
   public string Name {get;set;}

   [Phone]
   public string PhoneNumber {get;set;}

  [EmailAddress]
  public string Email {get;set;}
}

A Controller example:

public class PeopleController : Controller
{
   private readonly AddressBookContext _context;

   publicPeopleController(AddressBookContext context)
   {                
      _context = context;
   }
   // GET: /people 
   public async TaskIndex()
   {
      return View(await _context.People.ToListAsync());
   }

   // GET: /people/details/5 
   public async TaskDetails(int id)
   {
      var person =await _context.People.Find(id);
      if(person ==null)
      {
      return NotFound();
      }
      return View(person);
   }
}

A View example:

@model WebApplication1.Person

@Html.HiddenFor(x => x.PersonId )
<h2>Person Data</h2>
<div>
    @Model.PhoneNumber <br>
    @Model.Email<br>
</div>

For information on how the Models, Views, and Controllers interact and talk to each other, please visit the site listed above.


.NET Core also has a great information resource on Microsoft's site here: https://dotnet.microsoft.com/learn/aspnet/what-is-aspnet-core

A major difference between all other frameworks and Core is that the configuration values are stored differently. Core utilizes a JSON structure, rather than the traditional XML


In the below structures, you can see the Model, View, Controller folders to help you structure your project in a meaningful way. You can also see the 'appsettings.json' file in the Core solution. This file replaces the traditional 'web.config' file used in frameworks prior to Core.


On the left is the traditional MVC web application showing the Web.config. On the right is the Core framework showing the appsettings.json.


The next major difference is that Core applications can boast a massive performance boost. They have made the framework more lightweight, allowing quicker runtime.


Finally, ASP.NET apps can be developed and run on Windows, Linux, macOS, and Docker making it more accessible than prior frameworks.


For a deep dive into either the MVC architecture or the Core framework, follow the links provided.


15 views0 comments

Comments


bottom of page