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
411
votes
10 answers

Which version of MVC am I using?

I can't find it for some reason, feeling a little dumb. How do I know? I'm using .net 4 with VS2010.
EKet
  • 7,272
  • 15
  • 52
  • 72
406
votes
6 answers

How to secure an ASP.NET Web API

I want to build a RESTful web service using ASP.NET Web API that third-party developers will use to access my application's data. I've read quite a lot about OAuth and it seems to be the standard, but finding a good sample with documentation…
Craig Shearer
  • 14,222
  • 19
  • 64
  • 95
402
votes
10 answers

How to get current page URL in MVC 3

I am using the Facebook comments plugin on a blog I am building. It has some FBXML tags that are interpreted by the facebook javascript that is referenced on the page. This all works fine, but I have to pass in the current, fully-qualified URL to…
CatDadCode
  • 58,507
  • 61
  • 212
  • 318
401
votes
8 answers

Difference between ApiController and Controller in ASP.NET MVC

I've been playing around with ASP.NET MVC 4 beta and I see two types of controllers now: ApiController and Controller. I'm little confused at what situations I can choose a particular controller. For ex: If I want to return a view then I've to use…
VJAI
  • 32,167
  • 23
  • 102
  • 164
401
votes
22 answers

OwinStartup not firing

I had the OwinStartup configuration code working perfectly and then it stopped working. Unfortunately I'm not sure exactly what I did to get it to stop working and am having a really hard time figuring it out. To make sure I have the basics…
Jeff Treuting
  • 13,910
  • 8
  • 36
  • 47
393
votes
8 answers

Styles.Render in MVC4

In a .NET MVC4 project how does @Styles.Render works? I mean, in @Styles.Render("~/Content/css") which file is it calling? I dont have a file or a folder called "css" inside my Content folder.
Ricardo Polo Jaramillo
  • 12,110
  • 13
  • 58
  • 83
379
votes
23 answers

Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine

I have this section defined in my _Layout.cshtml @RenderSection("Scripts", false) I can easily use it from a view: @section Scripts { @*Stuff comes here*@ } What I'm struggling with is how to get some content injected inside this section…
tugberk
  • 57,477
  • 67
  • 243
  • 335
372
votes
9 answers

How to add Web API to an existing ASP.NET MVC 4 Web Application project?

I wish to add an ASP.NET Web API to an ASP.NET MVC 4 Web Application project, developed in Visual Studio 2012. Which steps must I perform to add a functioning Web API to the project? I'm aware that I need a controller deriving from ApiController,…
aknuds1
  • 65,625
  • 67
  • 195
  • 317
350
votes
3 answers

ValidateAntiForgeryToken purpose, explanation and example

Could you explain ValidateAntiForgeryToken purpose and show me example about ValidateAntiForgeryToken in MVC 4? I could not find any examples which explain this attribute?
Tabriz Atayi
  • 5,880
  • 7
  • 28
  • 33
349
votes
9 answers

How to pass json POST data to Web API method as an object?

ASP.NET MVC4 Web API application defines post method to save customer. Customer is passed in json format in POST request body. Customer parameter in post method contains null values for properties. How to fix this so that posted data will passed as…
Andrus
  • 26,339
  • 60
  • 204
  • 378
346
votes
8 answers

Returning binary file from controller in ASP.NET Web API

I'm working on a web service using ASP.NET MVC's new WebAPI that will serve up binary files, mostly .cab and .exe files. The following controller method seems to work, meaning that it returns a file, but it's setting the content type to…
Josh Earl
  • 18,151
  • 15
  • 62
  • 91
346
votes
71 answers

ASP.NET 5 MVC: unable to connect to web server 'IIS Express'

What I'm doing: Opening Visual Studio Community 2015 File -> New -> Project Under Visual C#: Web -> ASP.NET Web Application Web Application And press f5 for the popup error "unable to connect to web server 'IIS Express'." Deleting…
Sarek
  • 3,518
  • 2
  • 10
  • 9
345
votes
6 answers

HTML.ActionLink vs Url.Action in ASP.NET Razor

Is there any difference between HTML.ActionLink vs Url.Action or they are just two ways of doing the same thing? When should I prefer one over the other?
Pankaj Upadhyay
  • 12,966
  • 24
  • 73
  • 104
342
votes
6 answers

ASP.NET MVC View Engine Comparison

I've been searching on SO & Google for a breakdown of the various View Engines available for ASP.NET MVC, but haven't found much more than simple high-level descriptions of what a view engine is. I'm not necessarily looking for "best" or "fastest"…
mckamey
  • 17,359
  • 16
  • 83
  • 116
339
votes
17 answers

Validation failed for one or more entities while saving changes to SQL Server Database using Entity Framework

I want to save my Edit to Database and I am using Entity FrameWork Code-First in ASP.NET MVC 3 / C# but I am getting errors. In my Event class, I have DateTime and TimeSpan datatypes but in my database, I've got Date and time respectively. Could…
user522767
  • 4,013
  • 6
  • 21
  • 17