具体如下:1 .非Ajax前台:。
相应背景:
2.jQuery的Ajax在介绍使用JQuery提交表单之前,首先需要参考来自http://www.malsup.com/jquery/form/.的jquery.form.js到目前为止,我们需要参考的js文件有:。
函数:Ajax提交表单,在控制器HelloWorld4Controller中处理请求,并返回大量JSON格式的数据。首先我们假设返回的JSON实体为:复制代码如下:公共类loginresultto { public bool success { get;设置;}公共字符串Message { get设置;}公共字符串ReturnUrl { get设置;}}控制器部分的代码为:复制的代码如下: public class hello world 4 controller 3360 controller { public action result index(){ if(request . isajaxrequest()){ string R1=request . form[' text 33 '];字符串str2=请求。表单[' text 44 '];返回Json(新的MvcApplication5。controllers . hello world 3 controller . loginresultto { Success=true,Message=str1 str2,return URL=' some URL ' });} else { return View();}}}上面的代码告诉我们,如果要返回其他实体,是非常方便的。前台代码的一部分:
如果按钮没有使用submit,而是button,那么上面的代码就改成了下面的形式:。
源代码下载:MvcApplication5.zip