1

我有一个带有后期操作的控制器。使用javascript ajax 发布数据,action 参数始终为null。有什么建议吗?

路由

    config.Routes.MapHttpRoute(
        null,
        routeTemplate: "api/{controller}/{action}"
    );

阿贾克斯

public register(data: any): bool {
    var url = this.baseUrl + "Account/Register/";
    var xhr: JQueryXHR = $.ajax({
        type: "POST",
        url: url,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: { id: 0, "Username": "myUser", "Password" : "myPass" },
        async: false,
        cache: false,
    });
    return (xhr.status == 200);
}

行动

[HttpPost]
[AllowAnonymous]
[Mvc.ValidateAntiForgeryToken]
public void Register(UserLogin login)

用户登录

public class UserLogin
{
    public string Username { get; set; }
    public string Password { get; set; }
}
4

1 回答 1

2

尝试这个:

 data: JSON.stringify({ login : { id: 0, "Username": "myUser", "Password" : "myPass" }}),
于 2013-07-06T04:42:13.657 回答