2017-04-07 10 views
1
foreach (string key in HttpContext.Current.Request.Form.AllKeys) 
{ 
    string value = HttpContext.Current.Request.Form[key]; 
} 

위의 코드의 .net 핵심 버전은 무엇입니까? 마치 .net 코어가 꺼낸 것 같습니다. 올 키 그리고 으로 바 꾸었습니다. 위의 코드를 .net 핵심 방법으로 변환하려고 시도했지만 잘못된 연산 예외가 발생합니다.HttpContext.Current.Request.Form.AllKeys in ASP.NET CORE 버전

foreach (string key in HttpContext.Request.Form.Keys) 
{  
} 
+0

예외 메시지는 무엇입니까? – Tratcher

답변

3

당신이 사용할 수 있습니다

HttpContext.Request.Form = 'HttpContext.Request.Form은'System.InvalidOperationException '

변환 코드 유형의 예외가 발생했습니다 :

var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString()); 

그런 경우 사전 또는 ca를 반복 할 수 있습니다. n 값을 직접 액세스 :

dict["Hello"] = "World" 
+0

감사합니다. Gabriel – pavilion