7

What happened to FormCollections from System.Web.Mvc? In the past I would use something like this string value = data.GetValues(key).FirstOrDefault(); where data is a formcollection. Now when I try to implement a FormCollection it comes from Microsoft.AspNet.Http.Internal. Which doesnt contain the GetValues method.

I'm currently using beta 8 of MVC.

Mister Epic
  • 16,295
  • 13
  • 76
  • 147
HendPro12
  • 1,094
  • 3
  • 17
  • 50

2 Answers2

8

Seems like the form collection is now represented by the interface IFormCollection which inherits from IReadableStringCollection which is enumerable over the keys and values in the form collection passed in the http request. It can also be used to get to the values for a key through indexing:

var myValues = this.Request.Form[someKey];
Christian
  • 7,433
  • 4
  • 36
  • 61
3

You can access it via Request.Form in controllers. Instead of GetValues method, those values are accessed from it's indexer as:

var id = Request.Form["id"];

PS: If the given key does not exist, it does not return null or throw any exception. It returns StringValues.Empty instead.

Yves
  • 3,752
  • 4
  • 29
  • 43