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
538
votes
42 answers

ReSharper "Cannot resolve symbol" even when project builds

My Tools: Visual Studio 2012 Ultimate + Update 1 ReSharper v7.1.25.234 My Solution Build Status: Build Successfully But when I install ReSharper and ReSharper code analysis is enable, many keywords of my code are red with this error: "Cannot resolve…
Ramin Bateni
  • 16,499
  • 9
  • 69
  • 98
535
votes
21 answers

How to get all Errors from ASP.Net MVC modelState?

I want to get all the error messages out of the modelState without knowing the key values. Looping through to grab all the error messages that the ModelState contains. How can I do this?
chobo2
  • 83,322
  • 195
  • 530
  • 832
522
votes
4 answers

What is the difference between 'classic' and 'integrated' pipeline mode in IIS7?

I was deploying an ASP.NET MVC application last night, and found out that it is less work to deploy with IIS7 set to integrated mode. My question is what is the difference? And what are the implications of using one or the other?
Jon Erickson
  • 112,242
  • 44
  • 136
  • 174
512
votes
16 answers

How to render an ASP.NET MVC view as a string?

I want to output two different views (one as a string that will be sent as an email), and the other the page displayed to a user. Is this possible in ASP.NET MVC beta? I've tried multiple examples: 1. RenderPartial to String in ASP.NET MVC Beta If…
Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114
478
votes
20 answers

Can an ASP.NET MVC controller return an Image?

Can I create a Controller that simply returns an image asset? I would like to route this logic through a controller, whenever a URL such as the following is requested: www.mywebsite.com/resource/image/topbanner The controller will look up…
Jonathan
  • 32,202
  • 38
  • 137
  • 208
478
votes
16 answers

What is ViewModel in MVC?

I am new to ASP.NET MVC. I have a problem with understanding the purpose of a ViewModel. What is a ViewModel and why do we need a ViewModel for an ASP.NET MVC Application? If I get a good example about its working and explanation that would be…
unique
  • 5,442
  • 6
  • 23
  • 26
470
votes
13 answers

Using Razor within JavaScript

Is it possible or is there a workaround to use Razor syntax within JavaScript that is in a view (cshtml)? I am trying to add markers to a Google map... For example, I tried this, but I'm getting a ton of compilation errors:
raklos
  • 28,027
  • 60
  • 183
  • 301
461
votes
7 answers

Writing/outputting HTML strings unescaped

I've got safe/sanitized HTML saved in a DB table. How can I have this HTML content written out in a Razor view? It always escapes characters like < and ampersands to &.
AGS
  • 4,643
  • 2
  • 15
  • 4
446
votes
19 answers

How can I properly handle 404 in ASP.NET MVC?

I am using RC2 Using URL Routing: routes.MapRoute( "Error", "{*url}", new { controller = "Errors", action = "NotFound" } // 404s ); The above seems to take care of requests like this (assuming default route tables setup by initial…
Brian
  • 4,494
  • 3
  • 17
  • 7
438
votes
11 answers

ASP.NET MVC controller actions that return JSON or partial html

I am trying to create controller actions which will return either JSON or partial html depending upon a parameter. What is the best way to get the result returned to an MVC page asynchronously?
NathanD
  • 8,061
  • 7
  • 30
  • 26
433
votes
21 answers

Reflecting parameter name: abuse of C# lambda expressions or syntax brilliance?

I am looking at the MvcContrib Grid component and I'm fascinated, yet at the same time repulsed, by a syntactic trick used in the Grid syntax: .Attributes(style => "width:100%") The syntax above sets the style attribute of the generated HTML to…
Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
425
votes
7 answers

How to declare a local variable in Razor?

I am developing a web application in asp.net mvc 3. I am very new to it. In a view using razor, I'd like to declare some local variables and use it across the entire page. How can this be done? It seems rather trivial to be able to do the following…
vondip
  • 13,809
  • 27
  • 100
  • 156
418
votes
10 answers

ASP.NET Identity - HttpContext has no extension method for GetOwinContext

I have downloaded, and successfully ran the ASP.NET Identity sample from here: https://github.com/rustd/AspnetIdentitySample I am now in the middle of implementing the ASP.NET Identity framework in my project and have ran into a problem, that has…
Darren Wainwright
  • 30,247
  • 21
  • 76
  • 127
417
votes
5 answers

Why is JsonRequestBehavior needed?

Why is Json Request Behavior needed? If I want to restrict the HttpGet requests to my action I can decorate the action with the [HttpPost] attribute Example: [HttpPost] public JsonResult Foo() { return Json("Secrets"); } // Instead of: public…
gdoron
  • 147,333
  • 58
  • 291
  • 367
412
votes
6 answers

Getting full URL of action in ASP.NET MVC

Is there a built-in way of getting the full URL of an action? I am looking for something like GetFullUrl("Action", "Controller") that would return something like http://www.fred.com/Controller/Action. The reason I am looking for this is to avoid…
Alan Spark
  • 8,152
  • 8
  • 56
  • 91