【发布时间】:2011-05-13 07:41:33
【问题描述】:
您好,我加载了一个 JQuery 对话框,其中包含一个带有(目前)一个输入字段的表单。
我正在使用 MVC 3 和 JsonValueProviderFactory 来支持将 JSON 传递给我的操作方法。但我无法访问我的表单字段,因为对话框正在加载部分内容。
有谁知道用于访问加载到对话框中的表单字段的 JQuery。对话框代码是:
$('#Test').dialog({
bgiFrame: true,
autoOpen: false,
modal: true,
height: 400,
width: 500,
title: 'Add report',
draggable: true,
postion: 'center',
buttons: {
"save": function () {
$.ajax({
url: '/Test/Save',
type: "Post",
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function () {
alert("well done");
},
error: function () {
alert("error");
}
});
},
"cancel": function () {
$(this).dialog('close');
}
}
});
如您所见,我使用 JSON.stringify(data) 但尚未定义数据,因为我需要从表单值构造类型。顺便说一句,当我这样做时它可以工作,因为数据变量代表我的操作方法接收到的类型,但是我想从表单字段构造它
$('#Test').dialog({
bgiFrame: true,
autoOpen: false,
modal: true,
height: 400,
width: 500,
title: 'Add report',
draggable: true,
postion: 'center',
buttons: {
"save": function () {
var data = { Name: "Blah" };
$.ajax({
url: '/Test/Save',
type: "Post",
data: JSON.stringify(test),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function () {
alert("well done");
},
error: function () {
alert("error");
}
});
},
"cancel": function () {
$(this).dialog('close');
}
}
});
任何人都可以提供任何帮助将不胜感激。
【问题讨论】: