【发布时间】:2019-06-14 05:51:55
【问题描述】:
我正在从 jQuery 脚本调用 POST web-api,但数据未绑定。 Page 是 null
jQuery
$("document").ready(function(){
myTimer= setInterval( "StartTimer()", 1000);
});
function StartTimer()
{
$.ajax({
type: 'POST',
contentType: "application/x-www-form-urlencoded",
url: "/api/sitehit/LogHit/", //method Name
data: 'Page=test' ,
dataType: 'text/plain',
error: function (msg) {
alert(msg.responsetext);
}
}).fail(function () {
alert("error logging hit");
}).success(function () {
alert("success logging hit");
});
clearInterval(myTimer);
}
C# 代码
public class SiteHitController : ApiController
{
[HttpPost]
public void LogHit(string Page) // Page not binding
{
var c= Page; // Page is null
}
}
【问题讨论】:
-
没有帮助。我正在调用
API/Controller/Action/StringData但仍然没有结果 -
还要确保您的路由设置正确,因为没有为方法指定路由属性...
标签: c# jquery asp.net-mvc asp.net-web-api data-binding