我正在开发 Asp.net MVC 应用程序。在我的项目中,我使用了一个名为 Dhtmlx Scheduler 的第三方 JavaScript 库。 .
这个库中有一个函数可以将调度程序上的所有数据写入 XML 格式。 然后我需要操作这些数据,然后写回 <textarea>在我的 View 页面上。
到目前为止,这是我所拥有的:
查看:
function save() {
var url = "/Home/Save"
var xml = scheduler.toXML();
$.ajax({
url: url,
Type: "POST",
dataType: 'json',
async: false,
data: { xmlString: xml },
contentType: 'application/json; charset=utf-8',
success: alert("File Saved in C:\\ Drive as Tasks.xml")
});
}
Controller :
public ActionResult Save(string xmlString)
{
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(xmlString);
}
catch(Exception e)
{
Console.WriteLine(e);
}
doc.Save(@"C:\\Tasks.xml");
W6ViewModel viewModel = new W6ViewModel();
viewModel.engineers = db.W6ENGINEERS.ToList();
viewModel.tasks = db.W6TASKS.ToList();
viewModel.skills = db.W6TASKS_REQUIRED_SKILLS1.ToList();
viewModel.categories = db.W6TASKTYPECATEGORY.ToList();
gatherInfo(viewModel);
return View("Index", viewModel);
}
当试图保存三个事件(Dhtmlx 对象)时,它完美地工作,当试图向 XML 添加更多数据时,我得到这个错误(从 FireBug 读取):
The length of the query string for this request exceeds the configured maxQueryStringLength value.
如有任何帮助,我们将不胜感激。 谢谢!
Firebug 控制台:
请您参考如下方法:
我相信 jQuery.ajax 使用 type 而不是 Type。这是区分大小写的。如果您查看您的 Firebug,它正在执行 GET 请求而不是 POST:
$.ajax({
url: url,
Type: "POST",
dataType: 'json',
async: false,
data: { xmlString: xml },
contentType: 'application/json; charset=utf-8',
success: alert("File Saved in C:\\ Drive as Tasks.xml")
});
应该是
$.ajax({
url: url,
type: "POST",
dataType: 'json',
async: false,
data: { xmlString: xml },
contentType: 'application/json; charset=utf-8',
success: alert("File Saved in C:\\ Drive as Tasks.xml")
});
