我得到一個500(內部服務器錯誤),我不知道爲什麼。 我只想將一個JavaScript對象傳遞給C#函數。內部服務器錯誤:傳遞JavaScript對象到C#
這是JavaScript函數:
function validateImpact(id_dcr) {
$.ajax({
type: 'POST',
url: '/ModifyDocument/ImpactAssesment',
dataType: 'json',
data: {
id: 0,
quality: $("#quality").is(":checked"),
spares: $("#spares").is(":checked"),
supply: $("#supply").is(":checked"),
methods: $("#methods").is(":checked"),
mp: $("#mp").is(":checked"),
organization: $("#organization").is(":checked"),
procurement: $("#procurement").is(":checked"),
logistic: $("#logistic").is(":checked"),
health: $("#health").is(":checked"),
software: $("#software").is(":checked"),
details: $("#details").val(),
id_dcr: id_dcr
},
success: function (data) {
alert(data);
},
error: function (xhr, ajaxOptions, error) {
alert(xhr.status);
alert('Error: ' + xhr.responseText);
}
});
這是將在JavaScript函數來調用C#方法定義:
[HttpPost]
public ActionResult ImpactAssesment(Impact impact){
//Do something
return RedirectToAction("Index", "ModifyDocument");
}
這是C#類名 「影響」:
public partial class impact
{
[Key]
public int id { get; set; }
[Required]
public bool quality { get; set; }
[Required]
public bool spares { get; set; }
[Required]
public bool supply { get; set; }
[Required]
public bool methods { get; set; }
[Required]
public bool mp { get; set; }
[Required]
public bool organization { get; set; }
[Required]
public bool procurement { get; set; }
[Required]
public bool logistic { get; set; }
[Required]
public bool health { get; set; }
[StringLength(1073741823)]
public string details { get; set; }
[Required]
public bool software { get; set; }
[Required]
public int id_dcr { get; set; }
[ForeignKey("id_dcr")]
public virtual dcr dcr { get; set; }
}
'ImpactAssesment'不會返回代碼甚至不應該編譯的任何內容 – Dalorzo
@Dororzo yes確實如此。它正在返回:return RedirectToAction(「Index」,「ModifyDocument」); – AlwaysBeShels
調試AJAX請求時要做的第一件事;檢查控制檯的網絡選項卡以查看請求的狀態以及它拋出的錯誤消息 –