FormCollections missing from ASP.Net 5
Asked Answered
S

2

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.

Scales answered 16/10, 2015 at 19:56 Comment(0)
L
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];
Lighter answered 4/1, 2016 at 13:13 Comment(0)
A
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.

Acetylene answered 5/1, 2016 at 22:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.