A native mode:
1.POST (with ajax request as an example, we teach usage)
$.ajax({ type: "post", dataType: "json", cache: false, data: { method: "add" }, url: "../demo/post", async: true, success: function (data) { if (data.isOK) { alert("成功" ); } The else { Alert (" failure "); } } });
IFormCollection form = HttpContext.Request.Form; string method = form["method"];
2.GET (url mass participation as a case study, teach you use)
127.0.0.1/index/demo/get?num=1
IQueryCollection queryParameters = HttpContext.Request.Query; string num = queryParameters["num"];
Second, the parameters received in the form of the object (get / post General):
public class PageModel { public String TITLENAME { GET ; the SET ;} // Filter title public int CurrentPage { GET ; the SET ;} // this page public int NumCount { GET ; the SET ;} // page number of public Long Id { GET ; SET ;} = 0 ; // default ID public String the Token { GET ; SET ;} ="" ; // authentication and authorization }
public IActionResult UserList(PageModel pageModel) { return View(pageModel); }
Third, the route to achieve mass participation (get / post General):
127.0.0.1/Index/MenuDelAsync/1
public async Task<string> MenuDelAsync(long id) { string jsonResult = "[]"; bool b = false; b = await articleService.DelArticleTypeAsync(id); if (b) jsonResult = CommonHelper.NewGetJsonResult(1, "删除成功"); else jsonResult = CommonHelper.NewGetJsonResult(-1, "删除失败"); return jsonResult; }
Other uses are welcome to add comments, thank you!