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
324
votes
12 answers

Multiple models in a view

I want to have 2 models in one view. The page contains both LoginViewModel and RegisterViewModel. e.g. public class LoginViewModel { public string Email { get; set; } public string Password { get; set; } } public class RegisterViewModel { …
Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
309
votes
5 answers

ASP.NET MVC 3 - Partial vs Display Template vs Editor Template

So, the title should speak for itself. To create re-usable components in ASP.NET MVC, we have 3 options (could be others i haven't mentioned): Partial View: @Html.Partial(Model.Foo, "SomePartial") Custom Editor Template: @Html.EditorFor(model =>…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
294
votes
8 answers

Non-static method requires a target

I have a controller action that works fine on Firefox both locally and in production, and IE locally, but not IE in production. Here is my controller action: public ActionResult MNPurchase() { CalculationViewModel calculationViewModel =…
user547794
  • 14,263
  • 36
  • 103
  • 152
284
votes
4 answers

ReSharper warns: "Static field in generic type"

public class EnumRouteConstraint : IRouteConstraint where T : struct { private static readonly Lazy> _enumNames; // <-- static EnumRouteConstraint() { if (!typeof(T).IsEnum) { throw new…
bevacqua
  • 47,502
  • 56
  • 171
  • 285
278
votes
7 answers

Replace line break characters with
in ASP.NET MVC Razor view

I have a textarea control that accepts input. I am trying to later render that text to a view by simply using: @Model.CommentText This is properly encoding any values. However, I want to replace the line break characters with
and I can't…
bkaid
  • 51,465
  • 22
  • 112
  • 128
267
votes
8 answers

Using Ajax.BeginForm with ASP.NET MVC 3 Razor

Is there a tutorial or code example of using Ajax.BeginForm within Asp.net MVC 3 where unobtrusive validation and Ajax exist? This is an elusive topic for MVC 3, and I cannot seem to get my form to work properly. It will do an Ajax submit but…
JBeckton
  • 7,095
  • 13
  • 51
  • 71
261
votes
1 answer

Html5 data-* with asp.net mvc TextboxFor html attributes

How do I add data-* html attributes using TextboxFor? This is what I currently have: @Html.TextBoxFor(model => model.Country.CountryName, new { data-url= Url.Action("CountryContains", "Geo") }) As you see, the - is causing a problem here data-url.…
Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
258
votes
3 answers

@media media query and ASP.NET MVC razor syntax clash

I've got a large site that runs in ASP.NET MVC using the Razor view engine. I have a base stylesheet which contains all of the generic styling for the whole site. On occasion, however, I have page specific styles which in the of the page -…
Sniffer
  • 6,242
  • 10
  • 45
  • 53
253
votes
6 answers

What is the @Html.DisplayFor syntax for?

I understand that in Razor, @Html does a bunch of neat things, like generate HTML for links, inputs, etc. But I don't get the DisplayFor function... Why would I write: @Html.DisplayFor(model => model.Title) when I could just write: @Model.Title
Michael Pryor
  • 25,046
  • 18
  • 72
  • 90
252
votes
8 answers

How do I define a method in Razor?

How do I define a method in Razor?
Rookian
  • 19,841
  • 28
  • 110
  • 180
248
votes
6 answers

How to create a function in a cshtml template?

I need to create a function that is only necessary inside one cshtml file. You can think of my situation as ASP.NET page methods, which are min web services implemented in a page, because they're scoped to one page. I know about HTML helpers…
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
244
votes
42 answers

"Parser Error Message: Could not load type" in Global.asax

I'm working on an MVC3 project and receive the following error: Parser Error Message: Could not load type 'GodsCreationTaxidermy.MvcApplication'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.cs"…
PsychoCoder
  • 10,570
  • 12
  • 44
  • 60
241
votes
6 answers

An expression tree may not contain a call or invocation that uses optional arguments

An expression tree may not contain a call or invocation that uses optional arguments return this.RedirectToAction(x => x.Edit(merchantId)); Where edit had a second, nullable argument. Why is this?
bevacqua
  • 47,502
  • 56
  • 171
  • 285
238
votes
2 answers

ASP.NET MVC 3 Razor: Include JavaScript file in the head tag

I'm trying to figure out the proper Razor syntax to get a JavaScript file for a particular *.cshtml to be in the head tag along with all the other include files that are defined in _Layout.cshtml.
Stephen Patten
  • 6,333
  • 10
  • 50
  • 84
224
votes
23 answers

The type or namespace name does not exist in the namespace 'System.Web.Mvc'

Buiding MVC3 solution went well but have got an error in browser: Compiler Error Message: CS0234: The type or namespace name 'Html' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?) Source Error: Line 25: …
J.Olufsen
  • 13,415
  • 44
  • 120
  • 185