我已经用谷歌搜索了一整天,但仍然找不到答案。我需要POST
通过jQuery.post
toWeb API MVC-4
但无法获取数据。这是我的路由:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
这是我Controller
的(GET
作品!):
public string Get(int id)
{
return "value";
}
public void Post([FromBody]string data)
{
//body...
}
这是jQuery.post:
$.post('api/mycontroller', { key1: 'val1' });
任何的想法 ?
编辑:
@Darin:我试过这个:
public class UnitDetails{
public string id { get; set; }
}
和:
public void Post(UnitDetails id) {
//body...
}
和:
$.post('api/mycontroller', {id:'string1'});
但是我仍然想念一些东西..它并没有停止Post(...){...}
。再次 -Get(...){...}
有效..?