Questions tagged [asp.net-mvc-2]

ASP.NET MVC 2 is the second major version of the ASP.NET MVC platform, it has since been outdated by ASP.NET MVC 3.

According to Scott Guthrie's blog post on ASP.NET MVC 2, it has the following features:

  • New Strongly Typed HTML Helpers
  • Enhanced Model Validation support across both server and client
  • Auto-Scaffold UI Helpers with Template Customization
  • Support for partitioning large applications into “Areas”
  • Asynchronous Controllers support
  • Support for rendering sub-sections of a page/site using Html.RenderAction
  • Lots of new helper functions, utilities, and API enhancements
  • Improved Visual Studio tooling support

References:

MSDN ASP.NET MVC 2 Developer Reference

See for more information.

8449 questions
256
votes
9 answers

Download file of any type in Asp.Net MVC using FileResult?

I've had it suggested to me that I should use FileResult to allow users to download files from my Asp.Net MVC application. But the only examples of this I can find always has to do with image files (specifying content type image/jpeg). But what if…
Anders
  • 12,556
  • 24
  • 104
  • 151
233
votes
8 answers

Showing Difference between two datetime values in hours

I am retrieving two date time values from the database. Once the value is retrieved, I need the difference between the two values. For that, I create a timespan variable to store the difference of the 2 date values. TimeSpan? variable = datevalue1 -…
reggie
  • 13,313
  • 13
  • 41
  • 57
216
votes
4 answers

ModelState.AddModelError - How can I add an error that isn't for a property?

I am checking my database in Create(FooViewModel fvm){...} to see if the fvm.prop1 and fvm.prop2 already exist in that combination; if so, I want to add an error to the modelstate, then return the whole view. I tried: public ActionResult…
Scott Baker
  • 10,013
  • 17
  • 56
  • 102
215
votes
21 answers

jQuery Ajax calls and the Html.AntiForgeryToken()

I have implemented in my app the mitigation to CSRF attacks following the informations that I have read on some blog post around the internet. In particular these post have been the driver of my implementation Best Practices for ASP.NET MVC from…
Lorenzo
  • 29,081
  • 49
  • 125
  • 222
215
votes
13 answers

How to set a default value with Html.TextBoxFor?

Simple question, if you use the Html Helper from ASP.NET MVC Framework 1 it is easy to set a default value on a textbox because there is an overload Html.TextBox(string name, object value). When I tried using the Html.TextBoxFor method, my first…
dcompiled
  • 4,762
  • 6
  • 33
  • 36
158
votes
9 answers

How to specify an area name in an action link?

I have a shared master page which I am using from 2 different areas in my mvc 2 app. The master page has an action link which currently specifies the controller and action, but of course the link doesn't work if I'm in the wrong area. I see no…
Jeremy
  • 44,950
  • 68
  • 206
  • 332
147
votes
7 answers

How to write a simple Html.DropDownListFor()?

In ASP.NET MVC 2, I'd like to write a very simple dropdown list which gives static options. For example I'd like to provide choices between "Red", "Blue", and "Green".
Rinesse
  • 1,497
  • 2
  • 10
  • 5
147
votes
3 answers

What is the difference (if any) between Html.Partial(view, model) and Html.RenderPartial(view,model) in MVC2?

Other than the type it returns and the fact that you call it differently of course <% Html.RenderPartial(...); %> <%= Html.Partial(...) %> If they are different, why would you call one rather than the other one? The definitions: // Type:…
Stéphane
  • 11,755
  • 7
  • 49
  • 63
144
votes
5 answers

Url.Action parameters?

In listing controller I have, public ActionResult GetByList(string name, string contact) { var NameCollection = Service.GetByName(name); var ContactCollection = Service.GetByContact(contact); return View(new…
user787788
  • 1,575
  • 2
  • 9
  • 6
122
votes
13 answers

How to set a Default Route (To an Area) in MVC

Ok this has been asked before but there is no solid solution out there. So for purpose of myself and others who may find this useful. In MVC2 (ASP.NET) I want it so when someone navigates to the website, there is a default area specified. So…
LiamB
  • 18,243
  • 19
  • 75
  • 116
116
votes
4 answers

What are the Web.Debug.config and Web.Release.Config files for?

I just upgraded to Visual Studio 2010 and MVC 2.0 and I noticed the Web.config has two additional files attached to it? Are these files used to specify debug and release specific settings, so you don't clutter up the main Web.config? Does it even…
chobo
  • 31,561
  • 38
  • 123
  • 191
114
votes
20 answers

EditorFor() and html properties

Asp.Net MVC 2.0 preview builds provide helpers like Html.EditorFor(c => c.propertyname) If the property name is string, the above code renders a texbox. What if I want to pass in MaxLength and Size properties to the text box or my own css class…
chandmk
  • 3,496
  • 3
  • 21
  • 26
112
votes
2 answers

How do I use VaryByParam with multiple parameters?

In ASP.NET MVC2 I use OutputCache and the VaryByParam attribute. I got it working fine with a single parameter, but what is the correct syntax when I have several parameters on the method? [OutputCache(Duration=30, VaryByParam = "customerId"] public…
Frode Lillerud
  • 7,324
  • 17
  • 58
  • 69
110
votes
4 answers

What does Html.HiddenFor do?

Although I have read the documentation on Html.HiddenFor, I've not grasped what is it used for... Could somebody explain its uses and give a short example? Where should those helpers go in the code?
JPCF
  • 2,232
  • 5
  • 28
  • 50
98
votes
3 answers

GET and POST to same Controller Action in ASP.NET MVC

I'd like to have a single action respond to both Gets as well as Posts. I tried the following [HttpGet] [HttpPost] public ActionResult SignIn() That didn't seem to work. Any suggestions ?
Cranialsurge
  • 6,104
  • 7
  • 40
  • 39
1
2 3
99 100