Sharp Architecture ModelBinder 能否使用 jQuery ajax 请求正确构建对象?
您是否知道是否可以发出 AJAX 请求并让模型绑定器根据提供的参数正确构成对象?
例如:
$.ajax({
type: 'POST',
url: '../Create',
data: ( {
'SkillTypeRequest.Id': 0,
'SkillTypeRequest.Event.Id': eventId,
'SkillTypeRequest.SkillType.Id': skillTypeId,
'SkillTypeRequest.Division.Id': divisionId
} ),
success: function (data) { addSkillTypeRow( data ); }
});
测试控制器操作为:
public ActionResult Create(SkillTypeRequest request) { 返回 Json( 请求 ); 目前
,这在模型绑定器中失败,因为它试图将 null 分配给 SkillTypeRequest.Id。在我进一步调查之前,只是想确保这甚至可以开始,或者 Sharp/MVC 是否只允许通过表单进行这种类型的绑定?
Do you know if it's possible to make an AJAX request and have the model binder properly constitute an object based on the parameter provided?
For example:
$.ajax({
type: 'POST',
url: '../Create',
data: ( {
'SkillTypeRequest.Id': 0,
'SkillTypeRequest.Event.Id': eventId,
'SkillTypeRequest.SkillType.Id': skillTypeId,
'SkillTypeRequest.Division.Id': divisionId
} ),
success: function (data) { addSkillTypeRow( data ); }
});
The test controller action is:
public ActionResult Create(SkillTypeRequest request) {
return Json( request );
}
At the moment, this fails in the model binder because it's trying to assign null to the SkillTypeRequest.Id. Before I investigate further, just want to make sure this is even possible to begin with or does Sharp/MVC only allow this type of binding through forms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论