我正在尝试从jquery调用MVC Controller,但无法发出呼叫。下面的代码有什么问题吗
请找出是否有任何问题,而且我也没有任何错误。

url =“ http:// localhost:49917 / Account / SaveAddress”


this.SaveAddress = function (url, addressData)
    {
            $.ajax({
                type: "POST",
                url: url,
                dataType: "json",
                data: JSON.stringify(addressData),
                contentType: 'application/json; charset=utf-8',
                success: function (responseDetail) {
                   },
                error:function(e)
                {

                },
            });
    return 0;
};





public async Task<ActionResult> SaveAddress(AddressListViewModel addressListVM)
    {
        bool response;
        string message;
        if (addressListVM.ID <= 0)
        {
            response = await Task.Run(() => AccountManager.Instance().AddAddress(addressListVM));
            message = response ? "New address added successfully." : "Failed to add new address.";
        }
        else
        {
            response = await Task.Run(() => AccountManager.Instance().UpdateAddress(addressListVM));
            message = response ? "Selected address updated successfully." : "Failed to update selected address.";
        }
        ModelState.Clear();
        return Json(new { responsestatus = response, message = message }, JsonRequestBehavior.AllowGet);
        //return PartialView("_AddressDetail", BuildAddressListEntity(
        //                                UserManager.FindById(User.Identity.GetUserId()), response, message, addressListVM.ID, true));
    }

最佳答案

是的,您在this.saveaddress函数末尾缺少右括号

  this.SaveAddress = function (url, addressData)
  {
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: JSON.stringify(addressData),
            contentType: 'application/json; charset=utf-8',
            success: function (responseDetail) {
               },
            error:function(e)
            {

            },
        });


毕竟,..您还需要一个结束括号:

   }


;)

10-08 07:07