我有一个简单的帖子适用于测试应用程序
控制器代码
public ActionResult Delete(string Id) { ... delete record ... }
JavaScript的
function delAnnouncement(id) { $.ajax({ type: "POST",url: "@Url.Action("Delete","Announcements")",contentType: "application/json; charset=utf-8",data: JSON.stringify({ "Id": "03d23684-098a-4ae8-8fa2-7d9ce70d63ef" }),// Hard coded for testing success: function (data) { $("#AnnouncementsPH").replaceWith(data); } }); }
我创建了一个简单的测试应用程序,它在那里工作.
我正在寻找关于现有应用程序中可能存在的任何想法,这些想法总是会导致传递的id为null.
我尝试过的事情:
两个应用程序之间的路由信息是相同的.
它们都是安全的https网站.
现有网站上的其他表格按预期工作.这是使用带参数的javascript帖子的唯一地方.这只是列出任何系统公告的新视图.
据我所知,HTML是有效的.
提琴手显示数据正在发送.
我试图简单地在Id中传递硬代码.
我不知道是什么导致邮政不能工作.
谢谢你的任何建议
编辑1:这里是提琴手Raw帖子
POST https://localhost:44300/Announcements/Delete HTTP/1.1 Host: localhost:44300 Connection: keep-alive Content-Length: 39 Accept: */* Origin: https://localhost:44300 X-Requested-With: XMLHttpRequest Content-TypeOfNotification: application/json; charset=utf-8 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/36.0.1985.125 Safari/537.36 Content-Type: text/plain;charset=UTF-8 Referer: https://localhost:44300/ Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Cookie: jetbrains.charisma.main.security.PRINCIPAL=NmI4YmFhZTExMThjZDZkZjNmZTBhMDNiZWM4NmY3MDYzZWNiMWE3M2ZmZDM5ODMwYjViMjczN2ZkZmU3YmZlZTpyb290; TCSESSIONID=233EBE63123BA35468235F441F54D7E4; ASP.NET_SessionId=ycnx1ejeyahzipwduux2quqz; __RequestVerificationToken=FnOKGFfBZKEBX4E0KBoV9133e5KK3h9Pd_OjDzNPjv7ifMTMk5uHUPmT621hOQFyOCwW5IhdewKLPDMs2_9jY2vVwrHLYOU9f0F86mN-NoQ1; .AspNet.ApplicationCookie=V8ZnbAx_2_H1Wx946VLcQ235XplzC-uvKdw4CP7Sm8ZVnJu9pG63EuzC0ptOZZNBvzZkRjB0RJS25Pn1WHOzeQSrqoWl87keqRDS6_vMwZ9L6PgKU0rJz7OhD7eKps8l3tzR097zI5WbU_chUZFKLLw1c__rfN3Fy6BbHC1qNtgx0C86AShhG5EsNiruYqJZn-Uj7Z2h75YcZctCFniMyuzD-9RetcMjkN3_PbAJg-_urfntG9NwsMEQdBf1b3K9H3GP_wUYRhnbQdNZpuAkAEa6bVfJiHrnKFhnhLkP8BAfocbMKES1wQKbXBfcNn62cEKUu3On3lHNCNN4zEvOhxF1aDaBk-yghOtvtNkROeFTKMQFD0U-XXAf-RKm0Nwgp1Tb2Ip2U42vshDRNGXQSkOojisVUxiPmkrxDtckNycQd0br1cFSqxfeXyg3cg_vKUP1VMBQcBQxZO6MVLSCDdcpANyoE43IoLp3BHgURJZP88vF18JfVV646XGOZ3QU Id=03d23684-098a-4ae8-8fa2-7d9ce70d63ef
如您所见,Id已发布到控制器,只是未解析并提供给方法中的参数.
您可以附加参数,如:
原文链接:https://www.f2er.com/ajax/160188.htmlvar targeturl = '@Url.Action("Test","Controller")?id=' + ID; $.ajax({ url: targeturl,type: "GET",success: function(data) { },error: function (data) { } });
或者您可以直接使用jQuery ajax数据参数:
$.ajax({ type: "POST",url: '@Url.Action("Test","Controller")',data: { id: "your-id" } }) .done(function( msg ) { alert( "Data Saved: " + msg ); });