Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FormCollections missing from ASP.Net 5

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.

like image 340
HendPro12 Avatar asked Oct 16 '15 19:10

HendPro12


2 Answers

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];
like image 184
Christian Avatar answered Oct 25 '22 00:10

Christian


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.

like image 20
Yves Avatar answered Oct 24 '22 23:10

Yves