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
896
votes
9 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
  • 11,003
  • 5
  • 24
  • 30
874
votes
23 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,897
  • 4
  • 16
  • 6
784
votes
11 answers

How do I import a namespace in Razor View Page?

How to import a namespace in Razor View Page?
Amitabh
  • 59,111
  • 42
  • 110
  • 159
664
votes
16 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
  • 17,573
  • 4
  • 36
  • 44
477
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
  • 31,785
  • 25
  • 82
  • 101
461
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,643
  • 2
  • 15
  • 4
425
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,809
  • 27
  • 100
  • 156
417
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
  • 147,333
  • 58
  • 291
  • 367
379
votes
23 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
  • 57,477
  • 67
  • 243
  • 335
371
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,739
  • 18
  • 69
  • 95
366
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
  • 48,855
  • 59
  • 128
  • 165
345
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
  • 12,966
  • 24
  • 73
  • 104
343
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
  • 35,719
  • 63
  • 161
  • 257
337
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
  • 16,607
  • 10
  • 66
  • 101
332
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,667
  • 15
  • 58
  • 79
1
2 3
99 100