Questions tagged [asp.net-mvc-4]

ASP.NET MVC 4 is the fourth major version of the ASP.NET Model-View-Controller platform for web applications.

ASP.NET MVC 4 is the fourth major version of the ASP.NET Model-View-Controller platform for web applications.

New Features

Among the new features of the fourth release are:

  • Refreshed and modernized default project templates
  • New mobile project template
  • Many new features to support mobile apps
  • Enhanced support for asynchronous methods
  • ASP.NET Web API for HTTP services

Read the full feature list in the release notes

Resources

See for more information.

42411 questions
461
votes
7 answers

How to add reference to System.Web.Optimization for MVC-3-converted-to-4 app

I'm trying to use the new bundling feature in a project I recently converted from MVC 3 to MVC 4 beta. It requires a line of code in global.asax, BundleTable.Bundles.RegisterTemplateBundles();, which requires using System.Web.Optimization; at the…
Ian Davis
  • 19,091
  • 30
  • 85
  • 133
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
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
328
votes
6 answers

How do I set a cookie on HttpClient's HttpRequestMessage

I am trying to use the web api's HttpClient to do a post to an endpoint that requires login in the form of an HTTP cookie that identifies an account (this is only something that is #ifdef'ed out of the release version). How do I add a cookie to the…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
298
votes
16 answers

MVC4 StyleBundle not resolving images

My question is similar to this: ASP.NET MVC 4 Minification & Background Images Except that I want to stick with MVC's own bundling if I can. I'm having a brain crash trying to figure out what the correct pattern is for specifying style bundles…
Tom W Hall
  • 5,273
  • 4
  • 29
  • 35
280
votes
13 answers

How To Accept a File POST

I'm using asp.net mvc 4 webapi beta to build a rest service. I need to be able to accept POSTed images/files from client applications. Is this possible using the webapi? Below is how action I am currently using. Does anyone know of an example…
Phil
  • 4,134
  • 4
  • 23
  • 40
269
votes
28 answers

No connection string named 'MyEntities' could be found in the application config file

I am using entity framework and ASP.NET MVC 4 to build an application My solution is split into two projects; A class library that includes my data model (.edmx) file and a few custom interfaces The 'container' MVC project that references the class…
jjc99
  • 3,559
  • 4
  • 22
  • 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
260
votes
9 answers

Bundler not including .min files

I have a weird issue with the mvc4 bundler not including files with extension .min.js In my BundleConfig class, I declare public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/Scripts/jquery") …
Fatal
  • 3,338
  • 3
  • 19
  • 15
248
votes
3 answers

What is the _references.js used for?

What is the _references.js file used for in a new ASP.NET MVC 4 project?
Todd Smith
  • 17,084
  • 11
  • 59
  • 78
244
votes
8 answers

When should I use Async Controllers in ASP.NET MVC?

I have some concerns using async actions in ASP.NET MVC. When does it improve performance of my apps, and when does it not? Is it good to use async action everywhere in ASP.NET MVC? Regarding awaitable methods: shall I use async/await keywords when…
Vnuuk
  • 6,177
  • 12
  • 40
  • 53
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
233
votes
19 answers

OWIN Startup Class Missing

I'm getting this error as my project is not able to find the reference for OWIN startup class. I've even installed all the OWIN reference packages through Nuget still getting the same issue. I'm using Visual Studio 2012 and MVC4. The following…
Krunal Patil
  • 3,666
  • 5
  • 22
  • 28
1
2 3
99 100