Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';t向MVC控制器发送jQuery post数据_C#_Jquery_Asp.net Mvc - Fatal编程技术网

C# Can';t向MVC控制器发送jQuery post数据

C# Can';t向MVC控制器发送jQuery post数据,c#,jquery,asp.net-mvc,C#,Jquery,Asp.net Mvc,我尝试过从谷歌上找到的解决方案,但没有任何帮助。 我的ajax功能: $.ajax({ type: "post", url: apiEndpoint + "/CreateExercise", data: JSON.stringify(data), datatype: "json", contentType: "application/json", success: function (result)

我尝试过从谷歌上找到的解决方案,但没有任何帮助。 我的ajax功能:

$.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控制器:

public ActionResult CreateExercise(string sessionId, Exercise ExerciseCreateInfo)
我要发送的数据:

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 = {};

很抱歉,编写MVC控制器的人员使用了错误的命名空间。现在一切都好了。感谢您的帮助。

您可以通过以下几种方式向控制器发送数据: 在此示例中,您可以通过3种方式将数据发送到控制器:

  • Ajax.BeginForm
  • 模型
  • 视图模型
  • Jquery中的Ajax
  • FormCollection
  • 定义输入

  • 您遇到了什么样的错误?我可以在浏览器控制台中看到我的数据,但在服务器端,除了
    sessionId
    ExerciseCreateInfo也是您拥有的类型的名称吗?你能发布相关的对象(比如练习和任何子对象)吗?如果你发布了练习类的实现,这会很有帮助。