[英]get ajax posted Data From Request body
如何從請求正文中獲取這些ajax發布的數據?
search=title&searchType=department+1&X-Requested-With=XMLHttpRequest
您可以將[FromBody]
屬性用於需要從正文中獲取的參數。
Public ActionResult ([FromBody] string param1)
{
return View();
}
希望這會有所幫助。
您只需在控制器中將QueryString參數作為參數即可:
Public ActionResult Index(string search, string searchType,string XRequestedWith)
{
return View();
}
當然,這樣您的參數不能像X-Requested-With
這樣的破折號
您也可以使用Request.QueryString
來獲取QueryString。 這樣,您將沒有上述限制。
如果要從請求主體獲取那些用ajax發布的數據,那么第一條指令是不要將這些值放入查詢字符串中,而是將這些值放入表單主體中,最好是創建一個模式並使用這些屬性來傳遞ajax。
現在您將在操作方法中獲取這些值,例如
Public ActionResult YourMethodName([FromBody]YourModel objYourModel)
{
// use objYourModel to fetch your values
return View();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.