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.

8475 questions
240
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,086
  • 23
  • 97
  • 148
210
votes
20 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
  • 28,103
  • 43
  • 117
  • 208
205
votes
12 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,447
  • 6
  • 29
  • 34
199
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
  • 12,155
  • 10
  • 38
  • 53
198
votes
3 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
  • 8,951
  • 14
  • 46
  • 83
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
  • 40,978
  • 63
  • 191
  • 304
144
votes
2 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,129
  • 7
  • 41
  • 60
137
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,397
  • 2
  • 9
  • 5
128
votes
4 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,415
  • 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
  • 17,263
  • 19
  • 72
  • 112
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,456
  • 3
  • 19
  • 26
113
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
  • 29,453
  • 35
  • 118
  • 182
113
votes
9 answers

Making a Simple Ajax call to controller in asp.net mvc

I'm trying to get started with ASP.NET MVC Ajax calls. Controller: public class AjaxTestController : Controller { // // GET: /AjaxTest/ public ActionResult Index() { return View(); } public ActionResult FirstAjax() …
chamara
  • 12,019
  • 27
  • 120
  • 196
107
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,139
  • 5
  • 26
  • 47
107
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
  • 6,974
  • 15
  • 55
  • 69
1
2 3
99 100