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.

38553 questions
879
votes
8 answers

Entity Framework 5 Updating a Record

I have been exploring different methods of editing/updating a record within Entity Framework 5 in an ASP.NET MVC3 environment, but so far none of them tick all of the boxes I need. I'll explain why. I have found three methods to which I'll mention…
Stokedout
  • 10,803
  • 5
  • 21
  • 30
854
votes
22 answers

File Upload ASP.NET MVC 3.0

(Preface: this question is about ASP.NET MVC 3.0 which was released in 2011, it is not about ASP.NET Core 3.0 which was released in 2019) I want to upload file in asp.net mvc. How can I upload the file using html input file control?
user637197
  • 8,697
  • 4
  • 14
  • 6
760
votes
11 answers

How do I import a namespace in Razor View Page?

How to import a namespace in Razor View Page?
Amitabh
  • 51,891
  • 40
  • 102
  • 154
601
votes
15 answers

Escape @ character in razor view engine

I am creating a sample ASP.NET MVC 3 site using Razor as view engine. The razor syntax starts with @ character e.g. @RenderBody(). If I write @test on my cshtml page it gives me parse error CS0103: The name 'test' does not exist in the current…
ajay_whiz
  • 16,085
  • 3
  • 33
  • 44
439
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,423
  • 2
  • 13
  • 4
430
votes
7 answers

How to use ternary operator in razor (specifically on HTML attributes)?

With the WebForms view engine, I'll commonly use the ternary operator for very simple conditionals, especially within HTML attributes. For example: ">My link here The above code…
Portman
  • 30,925
  • 24
  • 79
  • 101
402
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 is supporting Monica
  • 136,782
  • 49
  • 273
  • 342
381
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,029
  • 27
  • 94
  • 151
365
votes
7 answers

How to set value of input text using jQuery

I have an input text which is this:
@Html.LabelFor(model => model.EmployeeId, "Employee Number")
@Html.EditorFor(model => model.EmployeeId) …
raberana
  • 11,870
  • 18
  • 62
  • 89
343
votes
25 answers

Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine

I have this section defined in my _Layout.cshtml @RenderSection("Scripts", false) I can easily use it from a view: @section Scripts { @*Stuff comes here*@ } What I'm struggling with is how to get some content injected inside this section…
tugberk
  • 54,046
  • 58
  • 232
  • 321
341
votes
17 answers

What's the difference between ViewData and ViewBag?

I saw the ViewBag in MVC 3. How's that different than ViewData in MVC 2?
user469652
  • 39,657
  • 56
  • 119
  • 161
328
votes
25 answers

Multiple types were found that match the controller named 'Home'

I currently have two unrelated MVC3 projects hosted online. One works fine, the other doesn't work, giving me the error: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this…
Only Bolivian Here
  • 32,571
  • 60
  • 151
  • 250
323
votes
6 answers

HTML.ActionLink vs Url.Action in ASP.NET Razor

Is there any difference between HTML.ActionLink vs Url.Action or they are just two ways of doing the same thing? When should I prefer one over the other?
Pankaj Upadhyay
  • 11,848
  • 24
  • 69
  • 100
322
votes
9 answers

Returning a file to View/Download in ASP.NET MVC

I'm encountering a problem sending files stored in a database back to the user in ASP.NET MVC. What I want is a view listing two links, one to view the file and let the mimetype sent to the browser determine how it should be handled, and the other…
Nick Albrecht
  • 15,828
  • 8
  • 64
  • 95
322
votes
3 answers

How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file?

I would like to have 2 separate Layouts in my application. Let's say one is for the Public section of the website and the other is for the Member side. For simplicity, let's say all the logic for each of these sites is wrapped neatly into 2 distinct…
Justin
  • 10,107
  • 14
  • 56
  • 76
1
2 3
99 100