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
252
votes
8 answers

How do I define a method in Razor?

How do I define a method in Razor?
Rookian
  • 19,841
  • 28
  • 110
  • 180
251
votes
43 answers

Error: «Could not load type MvcApplication»

I am getting the error Could not load type MvcApplication when I try to run my website. How to correct it?
Gil
  • 1,037
  • 4
  • 12
  • 14
248
votes
6 answers

How to create a function in a cshtml template?

I need to create a function that is only necessary inside one cshtml file. You can think of my situation as ASP.NET page methods, which are min web services implemented in a page, because they're scoped to one page. I know about HTML helpers…
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
247
votes
22 answers

How to handle checkboxes in ASP.NET MVC forms?

Caution: This question is over nine years old! Your best option is to search for newer questions, or to search the answers below looking for your specific version of MVC, as many answers here are obsolete now. If you do find an answer that works…
user1228
244
votes
10 answers

Is it possible to make an ASP.NET MVC route based on a subdomain?

Is it possible to have an ASP.NET MVC route that uses subdomain information to determine its route? For example: user1.domain.example goes to one place user2.domain.example goes to another? Or, can I make it so both of these go to the same…
Dan Esparza
  • 28,047
  • 29
  • 99
  • 127
243
votes
26 answers

Razor View throwing "The name 'model' does not exist in the current context"

After significant refactoring in my MVC 4 application, and Razor shows this error while debugging Views: The name 'model' does not exist in the current context. This is the offending line of code: @model ICollection I know…
keeehlan
  • 7,874
  • 16
  • 56
  • 104
241
votes
9 answers

Using Html.ActionLink to call action on different controller

I am trying to navigate between controllers using ActionLink. I will tell my problem with an example. I am on Index view of Hat controller, and I am trying to use below code to create a link to Details action of Product controller. <%=…
kaivalya
  • 4,611
  • 4
  • 26
  • 28
240
votes
11 answers

ViewModel Best Practices

From this question, it looks like it makes sense to have a controller create a ViewModel that more accurately reflects the model that the view is trying to display, but I'm curious about some of the conventions. Basically, I had the following…
jerhinesmith
  • 15,214
  • 17
  • 62
  • 89
239
votes
19 answers

HTML button calling an MVC Controller and Action method

I know this isn't right, but for the sake of illustration I'd like to do something like this: <%= Html.Button("Action", "Controller") %> My goal is to make an HTML button that will call my MVC controller's action method.
Aaron Salazar
  • 4,467
  • 10
  • 39
  • 54
238
votes
2 answers

ASP.NET MVC 3 Razor: Include JavaScript file in the head tag

I'm trying to figure out the proper Razor syntax to get a JavaScript file for a particular *.cshtml to be in the head tag along with all the other include files that are defined in _Layout.cshtml.
Stephen Patten
  • 6,333
  • 10
  • 50
  • 84
238
votes
13 answers

asp.net mvc: why is Html.CheckBox generating an additional hidden input

I just noticed that Html.CheckBox("foo") generates 2 inputs instead of one, anybody knows why is this so ?
Omu
  • 69,856
  • 92
  • 277
  • 407
238
votes
8 answers

How to return a file (FileContentResult) in ASP.NET WebAPI

In a regular MVC controller, we can output pdf with a FileContentResult. public FileContentResult Test(TestViewModel vm) { var stream = new MemoryStream(); //... add content to the stream. return File(stream.GetBuffer(),…
Blaise
  • 21,314
  • 28
  • 108
  • 169
236
votes
13 answers

What are the main disadvantages of Java Server Faces 2.0?

Yesterday I saw a presentation on Java Server Faces 2.0 which looked truly impressive, even though I am currently a happy ASP.NET MVC / jQuery developer. What I liked most about JSF was the huge amount of AJAX-Enabled UI components which seem to…
Adrian Grigore
  • 33,034
  • 36
  • 130
  • 210
234
votes
19 answers

Build error: You must add a reference to System.Runtime

I'm preparing a brand new ASP.NET MVC 5.1 solution. I'm adding in a bunch of NuGet packages and setting it up with Zurb Foundation, etc. As part of that, I've added a reference to an in-house NuGet package which is a Portable Class Library and I…
Luke Puplett
  • 42,091
  • 47
  • 181
  • 266
233
votes
4 answers

How to add ID property to Html.BeginForm() in asp.net mvc?

I want to validate my form using jquery but it doesn't have an ID property as of now how to add it to the form in asp.net mvc? I am using this... <% using (Html.BeginForm()) {%> and my jquery validator plugin takes this, var validator =…
ACP
  • 34,682
  • 100
  • 231
  • 371