内部服务器错误:将 JavaScript 对象传递给 C#
Internal Server Error : Passing JavaScript object to C#
我收到500(内部服务器错误),我不知道为什么。我只想将一个 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; }
}
看起来您使用的是MVC控制器(而不是Web api),因此您应该删除dataType: 'json'
选项
相关文章:
- 面向对象JavaScript中的私有函数
- 对象 Javascript 中的标签无效 - 想要添加事件列表器
- 将字符串转换为对象 javascript/jquery
- 正在检查对象javascript中是否存在嵌套属性
- 时间-日期对象JavaScript getUTCMilliseconds
- 仅在对象(javascript)中解析值
- 使用对象(JavaScript或jQuery)填充选择下拉列表
- 引用另一个对象javascript中的对象
- 如何删除列表中的对象?Javascript nodejs和下划线
- 无法从日期对象javascript获取日期和月份
- 如何在if语句中使用对象-Javascript
- 对象javascript错误
- 对象Javascript的少数实例
- 位置对象Javascript
- 将字符串传递到对象javascript中
- 获取对象Javascript或jQuery的最后一个值
- 鼠标接近对象Javascript
- 这个mixins代码是书中的错误吗;面向对象JavaScript的原理”;
- 使用闭包编译器编写更好的面向对象JavaScript完整示例代码
- 访问对象javascript数组中的对象属性值