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
177
votes
9 answers

StringLength vs MaxLength attributes ASP.NET MVC with Entity Framework EF Code First

What is the difference in behavior of [MaxLength] and [StringLength] attributes? As far as I can tell (with the exception that [MaxLength] can validate the maximum length of an array) these are identical and somewhat redundant?
Nick Goloborodko
  • 2,883
  • 3
  • 21
  • 38
177
votes
4 answers

How to use ? : if statements with Razor and inline code blocks

I'm updating my old .aspx views with the new Razore view engine. I have a bunch of places where I have code like this: ">Vote Up Ideally I'd like to do this:
Micah
  • 111,873
  • 86
  • 233
  • 325
168
votes
8 answers

Razor HtmlHelper Extensions (or other namespaces for views) Not Found

I don't know if this was happening in the PR or Beta, but if I create an extension method on HtmlHelper, it is not recognized in a Razor powered page: namespace SomeNamespace.Extensions { public static class HtmlExtensions { public…
swilliams
  • 48,060
  • 27
  • 100
  • 130
166
votes
6 answers

Do asynchronous operations in ASP.NET MVC use a thread from ThreadPool on .NET 4

After this question, it makes me comfortable when using async operations in ASP.NET MVC. So, I wrote two blog posts on that: My Take on Task-based Asynchronous Programming in C# 5.0 and ASP.NET MVC Web Applications Asynchronous Database Calls…
tugberk
  • 57,477
  • 67
  • 243
  • 335
164
votes
29 answers

The type or namespace name 'DbContext' could not be found

I am VERY new to ASP.NET MVC (3) and am having a hard time resolving a build error in Visual Studio: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) using System; using…
163
votes
7 answers

RestSharp JSON Parameter Posting

I am trying to make a very basic REST call to my MVC 3 API and the parameters I pass in are not binding to the action method. Client var request = new RestRequest(Method.POST); request.Resource = "Api/Score"; request.RequestFormat =…
Wesley Tansey
  • 4,555
  • 10
  • 42
  • 69
161
votes
12 answers

Dynamic Anonymous type in Razor causes RuntimeBinderException

I'm getting the following error: 'object' does not contain a definition for 'RatingName' When you look at the anonymous dynamic type, it clearly does have RatingName. I realize I can do this with a Tuple, but I would like to understand why the…
JarrettV
  • 18,845
  • 14
  • 46
  • 43
159
votes
1 answer

Correct way to use _viewstart.cshtml and partial Razor views?

I'm using _viewstart.cshtml to automagically assign the same Razor Layout to my views. It's a dead simple file in the root of my Views folder that looks like this: @{ Layout = "~/Views/Shared/_Layout.cshtml"; } This is more DRY than adding the…
Portman
  • 31,785
  • 25
  • 82
  • 101
158
votes
8 answers

Redirect to Action in another controller

I have two controllers, both called AccountController. One of them, lets call it Controller A, is in an Area called Admin and the other, lets call it Controller B, is not in any Area (I guess that means it's in the default Area?). Controller B has…
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
156
votes
7 answers

MVC 3: How to render a view without its layout page when loaded via ajax?

I am learning about Progressive Enhancement and I have a question about AJAXifying views. In my MVC 3 project I have a layout page, a viewstart page, and two plain views. The viewstart page is in the root of the Views folder and thus applies to all…
CatDadCode
  • 58,507
  • 61
  • 212
  • 318
155
votes
6 answers

Why does Razor _layout.cshtml have a leading underscore in file name?

In the default ASP.NET MVC 3 project, layout & partial cshtml files start with an underscore _viewstart _Layout _LogOnPartial Why this convention, and what is this used for? Do I need to follow this convention? Does the framework give some…
richb
  • 4,716
  • 5
  • 24
  • 22
154
votes
7 answers

How to elegantly deal with timezones

I have a website that is hosted in a different timezone than the users using the application. In addition to this, users can have a specific timezone. I was wondering how other SO users and applications approach this? The most obvious part is that…
TheCloudlessSky
  • 18,608
  • 15
  • 75
  • 116
151
votes
8 answers

Redirect From Action Filter Attribute

What is the best way to do a redirect in an ActionFilterAttribute. I have an ActionFilterAttribute called IsAuthenticatedAttributeFilter and that checked the value of a session variable. If the variable is false, I want the application to redirect…
ryanzec
  • 27,284
  • 38
  • 112
  • 169
148
votes
5 answers

How to add extra namespaces to Razor pages instead of @using declaration?

Is there some sort of magic I need to use to get the namespaces in the pages/namespaces element in the webconfig?
MyNameIsJob
  • 2,508
  • 2
  • 17
  • 17
146
votes
17 answers

Disable Required validation attribute under certain circumstances

I was wondering if it is possible to disable the Required validation attribute in certain controller actions. I am wondering this because on one of my edit forms I do not require the user to enter values for fields that they have already specified…
Alex Hope O'Connor
  • 9,354
  • 22
  • 69
  • 112