Questions tagged [asp.net-mvc-3]

ASP.NET MVC 3 is the third major version of Model-View-Controller extension for developing web applications in a .NET framework.

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

It supports the following new features:

Demos and Tutorials:

  1. Intro to ASP.NET MVC 3 (VB)
  2. Intro to ASP.NET MVC 3 (C#)

References:

See for more information.

38473 questions
222
votes
6 answers

ViewBag, ViewData and TempData

Could any body explain, when to use TempData ViewBag ViewData I have a requirement, where I need to set a value in a controller one, that controller will redirect to Controller Two and Controller Two will render the View. I have tried to use…
Hari Gillala
  • 11,736
  • 18
  • 70
  • 117
222
votes
15 answers

Setting Access-Control-Allow-Origin in ASP.Net MVC - simplest possible method

I have a simple actionmethod, that returns some json. It runs on ajax.example.com. I need to access this from another site someothersite.com. If I try to call it, I get the expected...: Origin http://someothersite.com is not allowed by…
Kjensen
  • 12,447
  • 36
  • 109
  • 171
214
votes
3 answers

what is the function of webpages:Enabled in MVC 3 web.config

I just started a new MVC 3 project. Can anyone tell me what in my web.config file does?
ftnilsson
  • 2,193
  • 2
  • 12
  • 10
212
votes
4 answers

ASP.NET MVC3 - textarea with @Html.EditorFor

I have ASP.NET MVC3 app and I have also form for add news. When VS2010 created default view I have only text inputs for string data, but I want to have textarea for news text. How I can do it with Razor syntax. Text input look like…
Jacob Jedryszek
  • 6,365
  • 10
  • 34
  • 39
211
votes
9 answers

Prevent Caching in ASP.NET MVC for specific actions using an attribute

I have an ASP.NET MVC 3 application. This application requests records through jQuery. jQuery calls back to a controller action that returns results in JSON format. I have not been able to prove this, but I'm concerned that my data may be getting…
JavaScript Developer
  • 3,968
  • 11
  • 41
  • 46
207
votes
7 answers

Where and how is the _ViewStart.cshtml layout file linked?

Here's the About.cshtml from the default MVC 3 template: @{ ViewBag.Title = "About Us"; }

About

Put content here.

I would expect that a reference to the _ViewStart file would be found in the About.cshtml, but clearly…
Kman
  • 4,809
  • 7
  • 38
  • 62
203
votes
4 answers

Access key value from Web.config in Razor View-MVC3 ASP.NET

How do I access a key value from web.config in my Razor view. This is in my web.config in the Web Project root level. I want to have to use the key in my Razor view. Thank you.
Hari Gillala
  • 11,736
  • 18
  • 70
  • 117
203
votes
15 answers

include antiforgerytoken in ajax post ASP.NET MVC

I am having trouble with the AntiForgeryToken with ajax. I'm using ASP.NET MVC 3. I tried the solution in jQuery Ajax calls and the Html.AntiForgeryToken(). Using that solution, the token is now being passed: var data = { ... } // with token, key is…
OJ Raqueño
  • 4,471
  • 2
  • 17
  • 30
202
votes
16 answers

ASP.NET MVC 3 Razor - Adding class to EditorFor

I'm trying to add a class to an input. This is not working: @Html.EditorFor(x => x.Created, new { @class = "date" })
user137348
  • 10,166
  • 18
  • 69
  • 89
196
votes
2 answers

How to write a comment in a Razor view?

How to write a comment in a MVC view, that won't be transmitted to the final HTML (i.e.,to browser, to response). One can make a comment with: but, it is visible in the page source code in browser. Is it possible…
horgh
  • 17,918
  • 22
  • 68
  • 123
193
votes
7 answers

EF LINQ include multiple and nested entities

Ok, I have tri-leveled entities with the following hierarchy: Course -> Module -> Chapter Here was the original EF LINQ statement: Course course = db.Courses .Include(i => i.Modules.Select(s => s.Chapters)) .Single(x…
AnimaSola
  • 7,146
  • 14
  • 43
  • 62
187
votes
10 answers

Add CSS or JavaScript files to layout head from views or partial views

Layout pages head: A View (AnotherView) from the application needs:
Nuri YILMAZ
  • 4,291
  • 5
  • 37
  • 43
187
votes
5 answers

Differences between Html.TextboxFor and Html.EditorFor in MVC and Razor

Why by default were these changed when adding a new "edit" view? What are advantages when using EditorFor() vs. TextboxFor()? I found this By default, the Create and Edit scaffolds now use the Html.EditorFor helper instead of the Html.TextBoxFor…
ShaneKm
  • 20,823
  • 43
  • 167
  • 296
187
votes
4 answers

Generic method multiple (OR) type constraint

Reading this, I learned it was possible to allow a method to accept parameters of multiple types by making it a generic method. In the example, the following code is used with a type constraint to ensure "U" is an IEnumerable. public T…
Mansfield
  • 14,445
  • 18
  • 76
  • 112
180
votes
3 answers

How to set web.config file to show full error message

I deployed my MVC-3 application on windows Azure. But now when I am requesting it through staging url it shows me (Sorry, an error occurred while processing your request.). Now I want to see the full error message, by default it is hiding that…
King Kong
  • 2,855
  • 5
  • 28
  • 39