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

Render Partial View Using jQuery in ASP.NET MVC

How do I render the partial view using jquery? We can render the partial View like this: <% Html.RenderPartial("UserDetails"); %> How can we do the same using jquery?
Prasad
  • 58,881
  • 64
  • 151
  • 199
232
votes
4 answers

What is an MvcHtmlString and when should I use it?

The documentation for MvcHtmlString is not terribly enlightening: Represents an HTML-encoded string that should not be encoded again. It's not clear to me what exactly the implications of this are. It seems that some HTML helper methods return an…
devuxer
  • 41,681
  • 47
  • 180
  • 292
232
votes
31 answers

Visual Studio 2012 Web Publish doesn't copy files

I have a Web Application project in VS 2012 and when I use the web publishing tool it builds successfully but doesn't copy any files to the publish target (File System in this case). If I look at the build output I can see everything gets copied…
229
votes
5 answers

Difference between Repository and Service Layer?

In OOP Design Patterns, what is the difference between the Repository Pattern and a Service Layer? I am working on an ASP.NET MVC 3 app, and am trying to understand these design patterns, but my brain is just not getting it...yet!!
Sam
  • 15,336
  • 25
  • 85
  • 148
228
votes
6 answers

Best way to implement request throttling in ASP.NET MVC?

We're experimenting with various ways to throttle user actions in a given time period: Limit question/answer posts Limit edits Limit feed retrievals For the time being, we're using the Cache to simply insert a record of user activity - if that…
Jarrod Dixon
  • 15,727
  • 9
  • 60
  • 72
228
votes
3 answers

Getting "The JSON request was too large to be deserialized"

I'm getting this Error: The JSON request was too large to be deserialized. Here's a scenario where this occurs. I have a class of country which hold a list of shipping ports of that country public class Country { public int Id { get; set; } …
Kayvan Karim
  • 2,986
  • 2
  • 18
  • 18
225
votes
4 answers

What is @RenderSection in asp.net MVC

What is the purpose of @RenderSection and how does it function? I understand what bundles do, but I have yet to figure out what this does and it's probably important. @RenderSection("scripts", required: false) Perhaps a small example on how to use…
Aflred
  • 4,435
  • 6
  • 30
  • 43
224
votes
8 answers

Put content in HttpResponseMessage object?

Several months ago, Microsoft decided to change up the HttpResponseMessage class. Before, you could simply pass a data type into the constructor, and then return the message with that data, but not anymore. Now, you need to use the Content property…
praetor
  • 3,195
  • 2
  • 23
  • 21
223
votes
6 answers

How to reference a .css file on a razor view?

I know how to set .css files on the _Layout.cshtml file, but what about applying a stylesheet on a per-view basis? My thinking here is that, in _Layout.cshtml, you have tags to work with, but not so in one of your non-layout views. Where do…
MrBoJangles
  • 12,127
  • 17
  • 61
  • 79
220
votes
10 answers

Where to place AutoMapper.CreateMaps?

I'm using AutoMapper in an ASP.NET MVC application. I was told that I should move the AutoMapper.CreateMap elsewhere as they have a lot of overhead. I'm not too sure how to design my application to put these calls in just 1 place. I have a web…
Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
220
votes
19 answers

How do I improve ASP.NET MVC application performance?

How do you improve your ASP.NET MVC application performance?
SDReyes
  • 9,798
  • 16
  • 53
  • 92
217
votes
4 answers

ASP.NET Identity DbContext confusion

A default MVC 5 App comes with this piece of code in IdentityModels.cs - this piece of code is for all the ASP.NET Identity operations for the default templates: public class ApplicationDbContext : IdentityDbContext { public…
216
votes
4 answers

What is the claims in ASP .NET Identity

Can somebody please explain, what the claim mechanism means in new ASP.NET Identity Core? As I can see, there is an AspNetUserLogins table, which contains UserId, LoginProvider and ProviderKey. But, I still can't understand or find any information…
Maxim Zhukov
  • 10,060
  • 5
  • 44
  • 88
215
votes
21 answers

jQuery Ajax calls and the Html.AntiForgeryToken()

I have implemented in my app the mitigation to CSRF attacks following the informations that I have read on some blog post around the internet. In particular these post have been the driver of my implementation Best Practices for ASP.NET MVC from…
Lorenzo
  • 29,081
  • 49
  • 125
  • 222
215
votes
3 answers

Do I need a Global.asax.cs file at all if I'm using an OWIN Startup.cs class and move all configuration there?

Let's say for example in a brand new ASP.NET MVC 5 application made from the MVC with Individual Accounts template, if I delete the Global.asax.cs class and move it's configuration code to Startup.cs Configuration() method as follow, what are the…
user681768