我使用以下代码发送ajax请求:
$.ajax({
url: "/Home/ShowStadium",
contentType: "application/json; charset=utf-8",
dataType: "text",
type: "POST",
data: Club,
success: function (data) {
$(".right-content").html(data);
},
error: function (xhr, textStatus) {
alert([xhr.status, textStatus]);
}
});
在HomeController中我有这个功能:
[HttpPost]
public ActionResult ShowStadium(){
if (Request.Form["Club"] == "Some text to compare")
{
return Content("First variant");
}
else
{
return Content("Second variant");
}
}
但我无法获取ajax发送的数据来进行比较。 Request.Form [“Club”] - 无法使用!
答案 0 :(得分:2)
用作
$.ajax({
url: "/Home/ShowStadium",
contentType: "application/json; charset=utf-8",
dataType: "text",
type: "POST",
data: {club:Club},
success: function (data) {
$(".right-content").html(data);
},
error: function (xhr, textStatus) {
alert([xhr.status, textStatus]);
}
});
在HomeController中我有这个功能:
[HttpPost]
public ActionResult ShowStadium(string club){
if (club == "Some text to compare")
{
return Content("First variant");
}
else
{
return Content("Second variant");
}
}