大佬教程收集整理的这篇文章主要介绍了jquery – 将json提交给MVC3动作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
ko.utils.postJson(LOCATIOn.href,ko.toJSON(viewmodel));
但是当它撞到服务器时,该对象是空白的.我切换到这段代码:
$.ajax({ url: LOCATIOn.href,type: "POST",data: ko.toJSON(viewmodel),datatype: "json",contentType: "application/json charset=utf-8",success: function (data) { alert("success"); },error: function (data) { alert("error"); } });
这会将数据传输到服务器,并在其中包含正确的数据.
它的要点是他创建了一个名为“FromJson”的属性,如下所示:
public class FromJsonAttribute : CustomModelBinderAttribute { private readonly static JavaScriptserializer serializer = new JavaScriptserializer(); public override IModelBinder GetBinder() { return new JsonModelBinder(); } private class JsonModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext,ModelBindingContext bindingContext) { var Stringified = controllerContext.httpContext.request[bindingContext.ModelName]; if (String.IsNullOrEmpty(Stringified)) return null; return serializer.Deserialize(Stringified,bindingContext.ModelTypE); } } }
然后,动作看起来像:
[httpPost] public ActionResult Index([FromJson] IEnumerable<GiftModel> gifts)
现在,您可以使用ko.utils.postJson提交数据并使用适当的视图进行响应.
以上是大佬教程为你收集整理的jquery – 将json提交给MVC3动作全部内容,希望文章能够帮你解决jquery – 将json提交给MVC3动作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。