Jyina
Jyina

Reputation: 2902

How to read Request.Form values in MVC view of asp.net core project?

I have asp.net core MVC project and I can't use Request.Form in a view to read form data. What is the alternative to read form data in asp.net core?

The name 'Request' does not exist in the current context.

@{
    ViewData["Title"] = "Index";
    string test = Request.Form["testdata"];   
}

Upvotes: 1

Views: 2983

Answers (1)

Ricardo Peres
Ricardo Peres

Reputation: 14555

Try this:

string test = Context.Request.Form["testdata"];

You need to prefix Request with Context.

Upvotes: 4

Related Questions