我正在将 dojo 1.8.3 与 asp.net mvc 一起使用。我被一个问题困住了。我正在尝试将来自一种表单的数据作为 JSON 发布(我有一个特定的理由发布为 json 而不是 JSON)。所以当我发布时,我在控制器端得到一个空字符串。下面是我的javascript代码
var xhrArgs = { url: rootPath + "Home/CreateNewPattern/",
postData: dojo.toJson({ Name: "name1", TimeSpan: "10" }),
handleAs: "text",
headers: { "Content-Type": "application/json", "Accept": "application/json" },
load: function (data) {
console.log("Create pattern form posted");
},
error: function (error) {
// We'll 404 in the demo, but that's okay. We don't have a 'postIt' service on the
// docs server.
alert("Error during Form posting");
}
}
// Call the asynchronous xhrGet
var deferred = dojo.xhrPost(xhrArgs);
我在控制器内的操作方法是
[HttpPost]
public ActionResult CreateNewPattern(string newPattern)
{
Trace.WriteLine("Name of the pattern is " + newPattern);
return RedirectToAction("DisplayPatternManagement");
}
谁能告诉我我做错了什么?