无法发送jQuery的岗位数据MVC控制器 [英] Can't send jQuery post data to MVC controller
本文介绍了无法发送jQuery的岗位数据MVC控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着从我能在谷歌找到解决办法,但没有任何帮助。
我的AJAX功能:
$。阿贾克斯({
类型:后,
网址:apiEndpoint +/ CreateExercise
数据:JSON.stringify(数据),
数据类型:JSON
的contentType:应用/ JSON
成功:函数(结果){
的console.log(结果); },
错误:功能(XHR,状态,P3,P4){
VAR ERR =错误++状态++ P3 ++ P4;
如果(xhr.responseText&安培;&安培; xhr.responseText [0] ==={){
ERR = JSON.parse(xhr.responseText).Message;
}
的console.log(ERR);
}
});
MVC控制器:
公众的ActionResult CreateExercise(字符串的sessionId,运动ExerciseCreateInfo)
这是我要发送数据:
data.sessionId =的sessionId;
data.ExerciseCreateInfo = {};
data.ExerciseCreateInfo.IsVisible = TRUE;
。data.ExerciseCreateInfo.SimilarityNorm = $(#numSimilarityScore)VAL();
data.ExerciseCreateInfo.TypeId = $(#selectTaskType选项:选择)VAL();
data.ExerciseCreateInfo.Name = $(#textTaskName)VAL()。
。data.ExerciseCreateInfo.Difficulty = $(#numDifficulty)VAL();
。data.ExerciseCreateInfo.MarkPoints = $(#为NumPoints)VAL();
data.ExerciseCreateInfo.Question = tinyMCE.get(editorTask)的getContent()。
data.ExerciseCreateInfo.Hint = tinyMCE.get(editorHint)的getContent()。
data.ExerciseCreateInfo.Explanation = tinyMCE.get(editorExpenation)的getContent()。
data.ExerciseCreateInfo.Fields = {};
解决方案
对不起,一个人,是谁写的MVC控制器使用错误的命名空间。现在,一切都很好。感谢您的帮助。
I've tried solutions from that I could find in Google, but nothing helped. My ajax function:
$.ajax({
type: "post",
url: apiEndpoint + "/CreateExercise",
data: JSON.stringify(data),
datatype: "json",
contentType: "application/json",
success: function (result) {
console.log(result);
},
error: function (xhr, status, p3, p4) {
var err = "Error " + " " + status + " " + p3 + " " + p4;
if (xhr.responseText && xhr.responseText[0] === "{") {
err = JSON.parse(xhr.responseText).Message;
}
console.log(err);
}
});
MVC controller:
public ActionResult CreateExercise(string sessionId, Exercise ExerciseCreateInfo)
Data that I want send:
data.sessionId = sessionId;
data.ExerciseCreateInfo = {};
data.ExerciseCreateInfo.IsVisible = true;
data.ExerciseCreateInfo.SimilarityNorm = $("#numSimilarityScore").val();
data.ExerciseCreateInfo.TypeId = $("#selectTaskType option:selected").val();
data.ExerciseCreateInfo.Name = $("#textTaskName").val();
data.ExerciseCreateInfo.Difficulty = $("#numDifficulty").val();
data.ExerciseCreateInfo.MarkPoints = $("#numPoints").val();
data.ExerciseCreateInfo.Question = tinyMCE.get("editorTask").getContent();
data.ExerciseCreateInfo.Hint = tinyMCE.get("editorHint").getContent();
data.ExerciseCreateInfo.Explanation = tinyMCE.get("editorExpenation").getContent();
data.ExerciseCreateInfo.Fields = {};
解决方案
Sorry, A person, who wrote MVC Controller used wrong namespace. Now everything is fine. Thanks for help.
这篇关于无法发送jQuery的岗位数据MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文