0

How to get these ajax posted data from request body ?

search=title&searchType=department+1&X-Requested-With=XMLHttpRequest

3 Answers3

0

You can use [FromBody] attribute to the parameter that you need to get from the body.

Public ActionResult ([FromBody] string param1)
{
    return View();
}

Hope this would help.

0

You can simply get QueryString paramaters as arguments in your Controller:

Public ActionResult Index(string search, string searchType,string XRequestedWith)
{
    return View();
}

Of course this way your paramater can not have dashes like X-Requested-With

You can also use Request.QueryString to get QueryString. This way you won't have the restriction above.

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
0

If you want to get those ajax posted data from request body the first instruction is not to put those values in query string put those values in form body.Better it would be if you create a modal and use those property to pass in ajax.

Now you would fetch those value in action method like

Public ActionResult YourMethodName([FromBody]YourModel objYourModel)
{
   // use objYourModel to fetch your values
   return View();
}