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
145
votes
6 answers

Custom error pages on asp.net MVC3

I'm developing a MVC3 base website and I am looking for a solution for handling errors and Render custom Views for each kind of error. So imagine that I have a "Error" Controller where his main action is "Index" (generic error page) and this…
João Louros
  • 2,752
  • 4
  • 23
  • 30
140
votes
4 answers

ASP.NET MVC: Is Controller created for every request?

Very simple question: Are controllers in ASP.NET created for every HTTP request, or are they created at application startup and reused throughout requests? Will the controller be created only for a particular HTTP request? If my previous assumptions…
Rasto
  • 17,204
  • 47
  • 154
  • 245
139
votes
1 answer

How to write "Html.BeginForm" in Razor

If I write like this: form action="Images" method="post" enctype="multipart/form-data" it works. But in Razor with '@' it doesn't work. Did I make any mistakes? @using (Html.BeginForm("Upload", "Upload", FormMethod.Post, …
kk-dev11
  • 2,654
  • 5
  • 37
  • 48
139
votes
6 answers

MVC3 Razor: Displaying html within code blocks

In my cshtml files I have a lot of blocks with stuff like this: @if(Model.foo) { Hello World } The only reason the span is there is because I can't find any other way to force it to recognize that "Hello World" is part of the html…
DMulligan
  • 8,993
  • 6
  • 33
  • 34
138
votes
3 answers

Convert HttpPostedFileBase to byte[]

In my MVC application, I am using following code to upload a file. MODEL public HttpPostedFileBase File { get; set; } VIEW @Html.TextBoxFor(m => m.File, new { type = "file" }) Everything working fine .. But I am trying to convert the result fiel…
Null Pointer
  • 9,089
  • 26
  • 73
  • 118
137
votes
5 answers

ASP.NET: This method cannot be called during the application's pre-start initialization stage

I'm trying to get an ASP.NET MVC 3 site running on IIS 6.0. Currently when I request a page from the server it gives the following error: Parser Error Message: This method cannot be called during the application's pre-start initialization…
sqwerty
  • 1,773
  • 2
  • 14
  • 14
136
votes
4 answers

ASP.Net MVC Html.HiddenFor with wrong value

I'm using MVC 3 in my project, and I'm seeing a very strange behavior. I'm trying to create a hidden field for a particular value on my Model, the problem is that for some reason the value set on the field does not correspond to the value in the…
willvv
  • 8,439
  • 16
  • 66
  • 101
136
votes
9 answers

Method not found: '!!0[] System.Array.Empty()'

I created a new app with VS 2015 RC and the MVC template and without modifying any line of code I have this error: Method not found: '!!0[] System.Array.Empty()'. Description: An unhandled exception occurred during the execution of the current web…
Luis Valencia
  • 32,619
  • 93
  • 286
  • 506
131
votes
7 answers

How to create a readonly textbox in ASP.NET MVC3 Razor

How do I create a readonly textbox in ASP.NET MVC3 with the Razor view engine? Is there an HTMLHelper method available to do that? Something like the following? @Html.ReadOnlyTextBoxFor(m => m.userCode)
Shyju
  • 214,206
  • 104
  • 411
  • 497
131
votes
8 answers

Get current controller in view

I have a View - _Edit which lives in News M/V/C. I reuse the V/M via the CategoryController as: return PartialView("/Views/News/_Edit.cshtml", model); How from within the View - _Edit can I alert the controller name? When I: alert('@ViewContext.…
Valamas
  • 24,169
  • 25
  • 107
  • 177
131
votes
4 answers

Razor comment syntax

What is the syntax for server side comment in razor view? I want to comment this code: /* @helper NavItem() { } */
stacker
  • 14,641
  • 17
  • 46
  • 74
130
votes
4 answers

request exceeds the configured maxQueryStringLength when using [Authorize]

I have a MVC3 site in C#, I have a particular view being fed query parameters from a JavaScript function, the function redirects to the site via window.location.href = "../ActionName?" + query_string; query_string being the dynamic query…
Sabre
  • 2,350
  • 2
  • 18
  • 25
130
votes
3 answers

How to use knockout.js with ASP.NET MVC ViewModels?

Bounty It's been awhile and I still have a couple outstanding questions. I hope by adding a bounty maybe these questions will get answered. How do you use html helpers with knockout.js Why was document ready needed to make it work(see first edit…
chobo2
  • 83,322
  • 195
  • 530
  • 832
128
votes
9 answers

Application_Error not firing when customerrors = "On"

I have code in the global.asax file's Application_Error event which executes when an error occurs and emails details of the error to myself. void Application_Error(object sender, EventArgs e) { var error = Server.GetLastError(); if…
William
  • 8,007
  • 5
  • 39
  • 43
128
votes
9 answers

Int or Number DataType for DataAnnotation validation attribute

On my MVC3 project, I store score prediction for football/soccer/hockey/... sport game. So one of properties of my prediction class looks like this: [Range(0, 15, ErrorMessage = "Can only be between 0 .. 15")] [StringLength(2, ErrorMessage = "Max 2…
Antonin Jelinek
  • 2,277
  • 2
  • 20
  • 25