我在 .net 4.0 Web 表单 Web 应用程序上使用 Web api 执行以下控制器操作。
public dynamic Post(Guid id, string adminNotes = "", string artNotes = "")
        {
            dynamic response = new ExpandoObject();
            response.Success = false;
            Udac udac = CustomerUdacs.Where(x => x.EditKey == id).FirstOrDefault();
            if (udac != null)
            {
                udac.AdminNotes = adminNotes.Trim();
                udac.ArtNotes = artNotes.Trim();
                response.Success = true;
            }
            return response;
        }
我正在使用 jQuery ajax() 来发布数据。我使用 Guid 作为我的 id(存储在我的 javascript 中的 ajax_edit_key 中)。当我使用这个时:
$.ajax({
                    type: "POST",
                    url: "/api/notes/"+ajax_edit_key,
                    data: { adminNotes: $("#tbEditNotesAdmin").val(), artNotes: $("#tbEditNotesArt").val() }
                }).done(function (data) {
                    if (data.Success) {
                        $("#tbEditNotesAdmin").val(''); //td.id-notes-admin
                        $("#tbEditNotesArt").val(''); //td.id-notes-art
                        ajax_edit_key = '';
                        $dialog.dialog("close");
                    }
                }).fail(function () {
                    alert('fail');
                });
它调用该操作,但我的 adminNotes 和 artNotes 从浏览器作为空字符串传递。
如果我更改 url 以在查询字符串中包含参数,它可以正常工作。
url: "/api/notes/"+ajax_edit_key+"?"+ "adminNotes="+$('#tbEditNotesAdmin').val()+"&artNotes="+$('#tbEditNotesArt').val()
//data: { adminNotes: $("#tbEditNotesAdmin").val(), artNotes: $("#tbEditNotesArt").val() }
为什么是这样?我怎样才能让它使用数据参数