Questions tagged [asp.net-mvc]

The ASP.NET MVC Framework is an open source web application framework and tooling that implements a version of the model-view-controller (MVC) pattern tailored towards web applications and built upon an ASP.NET technology foundation.

Microsoft ASP.NET MVC Framework is an open-source web application framework and tooling that implements a version of the model-view-controller (MVC) pattern tailored towards web applications.

ASP.NET MVC Framework provides an alternative to the ASP.NET WebForms Framework for creating Web applications and is a more lightweight and testable framework than its WebForms cousin, even though they are both built upon the same base ASP.NET Foundation. It uses existing ASP.NET features, and in more recent versions has become more unified with WebForms via Microsoft's "One ASP.NET" initiative. The MVC framework is defined in the System.Web.Mvc assembly.

releases also tend to package additional technologies, such as the Razor View Engine, Web Optimization Framework, ASP.NET WebAPI, along with tooling such as Scaffolding and integration into Visual Studio.

The Model-View-Controller architectural pattern, upon which ASP.NET MVC is based separates an application into three main components: the model, the view, and the controller. The reason for this separation is to provide a cleaner overall architecture, while improving maintainability. This concept is often referred to as a "Separation of Concerns."

A model represents the state of a particular aspect of the application. Frequently, a model maps to a database table with the entries in the table representing the state of the application. A controller handles interactions and updates the model to reflect a change in state of the application, and then passes information to the view. A view accepts necessary information from the controller and renders a user interface to display that.

Since the ASP.NET MVC 4 release, Microsoft has shipped the framework both with a specific release of Visual Studio, as well as via the Nuget package management system. This package management method allows for easier "out of band" releases (versions not tied to a specific version of Visual Studio), along with a more module release so that sub-components can be chosen to be included or not (ASP.NET WebApi for example).

The latest announcements from Microsoft regarding ASP.NET MVC usually come from the .NET Web Development and Tools Blog, Visual Studio Blog or .NET Framework Blog. Other notable blogs relating to MVC are Scott Guthrie's Blog, ASP.NET by Scott Hanselman and Imran Baloch's Blog.

Unless you have a good reason not to, try to keep your MVC version current. There are bug fixes in newer versions, as well as new features. It makes little sense to create new projects using older versions of MVC today. The first thing you should do after creating a new project is open up the NuGet package manager and apply all updates (with the possible exception of jQuery 2.x. If you need compatibility with older browsers stay with the latest version jQuery 1.x, which is feature compatible with the 2.x line).

Versions shipped with Visual Studio

  • Visual Studio 2017 - ASP.NET MVC 5.2.3 - ASP.NET Core MVC 1.1.2
  • Visual Studio 2015 - ASP.NET MVC 5.2.0
  • Visual Studio 2013 - ASP.NET MVC 5.1.0
  • Visual Studio 2012 - ASP.NET MVC 5.0.0
  • Visual Studio 2010 - ASP.NET MVC 2 (no point releases)
  • Visual Studio 2008 - None (MVC was released after 2008 was)

Requirements by version

  • MVC 5.x - Visual Studio 2012 - CLR 4.0 - Framework 4.5
  • MVC 4 - Visual Studio 2010 - CLR 4.0 - Framework 4.0
  • MVC 3 - Visual Studio 2010 - CLR 4.0 - Framework 4.0
  • MVC 2 - Visual Studio 2008 - CLR 2.0
  • MVC 1 - Visual Studio 2008 - CLR 2.0

Current Releases (Available through NuGet) * Stable release 5.2.3 (February 9, 2015)

References

Frequently Asked Questions (FAQ)

Please note that most questions that may refer to a specific version of ASP.NET MVC will likely apply to newer versions as well. So if the question says MVC3, it likely also applies to MVC4 and MVC5.x, etc.

Tutorials (High quality external articles on Frequently asked topics)

200910 questions
269
votes
11 answers

Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing

I had an Asp.Net core 2.2 project. Recently, I changed the version from .net core 2.2 to .net core 3.0 Preview 8. After this change I see this warning message: using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To…
Nick Mehrdad Babaki
  • 11,560
  • 15
  • 45
  • 70
268
votes
24 answers

ASP.NET MVC JsonResult Date Format

I have a controller action that effectively simply returns a JsonResult of my model. So, in my method I have something like the following: return new JsonResult(myModel); This works well, except for one problem. There is a date property in the…
Jon Archway
  • 4,852
  • 3
  • 33
  • 43
268
votes
21 answers

HTTP Error 500.19 and error code : 0x80070021

I have a simple webAPI build by Visual Studio 2013. It works well when I run it from VS13 but when I copy the project in local IIS it gives me the following error. HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed…
Umar Abbas
  • 4,041
  • 2
  • 23
  • 21
268
votes
11 answers

How to make custom error pages work in ASP.NET MVC 4

I want a custom error page shown for 500, 404 and 403. Here's what I have done: Enabled custom errors in the web.config as follows:
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
267
votes
8 answers

Using Ajax.BeginForm with ASP.NET MVC 3 Razor

Is there a tutorial or code example of using Ajax.BeginForm within Asp.net MVC 3 where unobtrusive validation and Ajax exist? This is an elusive topic for MVC 3, and I cannot seem to get my form to work properly. It will do an Ajax submit but…
JBeckton
  • 7,095
  • 13
  • 51
  • 71
264
votes
10 answers

HTML.ActionLink method

Let's say I have a class public class ItemController:Controller { public ActionResult Login(int id) { return View("Hi", id); } } On a page that is not located at the Item folder, where ItemController resides, I want to create a…
Graviton
  • 81,782
  • 146
  • 424
  • 602
262
votes
6 answers

ASP.NET MVC Razor render without encoding

Razor encodes string by default. Is there any special syntax for rendering without encoding?
SiberianGuy
  • 24,674
  • 56
  • 152
  • 266
261
votes
1 answer

Html5 data-* with asp.net mvc TextboxFor html attributes

How do I add data-* html attributes using TextboxFor? This is what I currently have: @Html.TextBoxFor(model => model.Country.CountryName, new { data-url= Url.Action("CountryContains", "Geo") }) As you see, the - is causing a problem here data-url.…
Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
261
votes
10 answers

Preprocessor directives in Razor

I am writing my first Razor page today, and can't figure out how to enter #if debug ... #else ... #endif How can I do that in Razor?
mamu
  • 12,184
  • 19
  • 69
  • 92
260
votes
9 answers

Serving favicon.ico in ASP.NET MVC

What is the final/best recommendation for how to serve favicon.ico in ASP.NET MVC? I am currently doing the following: Adding an entry to the very beginning of my RegisterRoutes method: routes.IgnoreRoute("favicon.ico"); Placing favicon.ico in the…
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
260
votes
14 answers

How to cache data in a MVC application

I have read lots of information about page caching and partial page caching in a MVC application. However, I would like to know how you would cache data. In my scenario I will be using LINQ to Entities (entity framework). On the first call to…
Coolcoder
  • 4,036
  • 6
  • 28
  • 35
257
votes
6 answers

How to return a 200 HTTP Status Code from ASP.NET MVC 3 controller

I am writing an application that is accepting POST data from a third party service. When this data is POSTed I must return a 200 HTTP Status Code. How can I do this from my controller?
Paul Brown
  • 4,926
  • 9
  • 32
  • 44
256
votes
18 answers

NUnit vs. Visual Studio 2008's test projects for unit testing

I am going to be starting up a new project at work and want to get into unit testing. We will be using Visual Studio 2008, C#, and the ASP.NET MVC stuff. I am looking at using either NUnit or the built-in test projects that Visual Studio 2008 has,…
Ryan Skarin
  • 3,087
  • 3
  • 21
  • 18
254
votes
5 answers

MVC 4 Razor File Upload

I am new to MVC 4 and I am trying to implement File Upload Control in my website. I am not able to find the mistake.I am getting a null value in my file. Controller: public class UploadController : BaseController { public ActionResult…
user2028367
253
votes
9 answers

How do I find the absolute url of an action in ASP.NET MVC?

I need to do something like this: I'm using the Beta version of MVC, but I can't figure out how to get the absolute url of an action. I'd like to do…
Mike Comstock
  • 6,640
  • 10
  • 36
  • 41