各位好,我在学习EXTjs+ASP.NET+MVC表单的时候遇到这样一个问题,请大家指教:
问题背景:在ASP.NET+MVC的VIEW里面添加EXT代码,是一个提交表单,代码如下:
- JScript code
<script type="text/javascript"> var form; Ext.onReady(function () { form = new Ext.form.FormPanel({ baseCls: 'x-plain', layout: 'absolute', //url: 'http://localhost:1683/Handler1.ashx', defaultType: 'textfield', items: [{ x: 0, y: 5, xtype: 'label', text: '收件人:' }, { x: 60, y: 0, name: 'to', anchor: '100%' // anchor width by percentage }, { x: 0, y: 35, xtype: 'label', text: '主题:' }, { x: 60, y: 30, name: 'subject', anchor: '100%' // anchor width by percentage }, { x: 0, y: 60, xtype: 'textarea', name: 'msg', anchor: '100% 100%' // anchor width and height }] }); var window = new Ext.Window({ title: '发送邮件', width: 500, height: 300, minWidth: 300, minHeight: 200, layout: 'fit', plain: true, bodyStyle: 'padding:5px;', buttonAlign: 'center', items: form, buttons: [{ text: '发送', handler: submit }, { text: '取消' }] }); window.show(); }); function submit() { if (!form.getForm().isValid()) return; form.getForm().submit({ waitMsg: '正在提交数据', waitTitle: '提示', //url: '../../Handler1.ashx', url: 'Home/GGG', method: 'GET', success: function (form, action) { Ext.Msg.alert('提示', '保存成功啊啊'); }, failure: function (form, action) { Ext.Msg.alert('提示', '原因如下:' + action.result.errors.info); } }); } </script>
GGG动作的代码如:
- C# code
public ActionResult GGG() { //Response.Write("{ success: false, errors:{info: '错误了'} }"); Response.Write("{success:true}"); Response.End(); return View(); }
问题描述:
在使用默认地址:http://localhost:7537/访问的时候,表单正常,点击提交,出现成功提示“保存成功啊啊”,控制器里面打断点,能停住
但是当从其他页面跳转过来,或者使用http://localhost:7537/home/Index路径访问这个页面的时候,点击提交,会出现JS脚本错误“result.errors为空或不是对象”。后台打断点,不能停住,不知道原因是什么,希望各位能够不吝赐教,谢谢!
------解决方案--------------------
- CSS code
那就是你访问的页面出现异常了,看看是哪里出现错误了。看看这个请求执行了那个页面的代码