如何设置从视图到模型的值?

时间:2015-02-03 11:28:25

标签: jquery asp.net-mvc

我在mvc中有我的jquery,从视图中获取值并设置为模型值。但是我无法实现。 注意:使用“alert”方法验证的值越来越完美。 请告诉我如何实现这一目标。 我的代码看起来像,

 $('#AssignButton').button().click(function () {
        var $selectedRows = $('#NotAllotedStudentsGrid').jtable('selectedRows');
        var selectedRowsList = [];
        var i = 0;
        $selectedRows.each(function () {
            var record = $(this).data('record');
            selectedRowsList[i] = record.UserNo;
            i++;
        });
        var LimitQuestionCount = $("#LimitQuestionCount").val();
        if (selectedRowsList.length > 0) {
            var options = {};
            options.type = "POST";
            options.url = "/Dashboard/AllotQuestionSet/";
            options.data = JSON.stringify({ selectedStudents: selectedRowsList, model: { Effective_date: $("#Effectivedate").val(), Expiry_date: $("#duedate").val(), LimitQuestionCount: $("#LimitQuestionCount").val() } });
            alert($("#Effectivedate").val());
            alert($("#duedate").val());
            alert($("#LimitQuestionCount").val());
            alert(selectedRowsList);
            options.dataType = "json";
            $.ajax(options);
            alert("ajaxCall");
            window.location.href = "/Account/ApplInfo/";
        }
    });

1 个答案:

答案 0 :(得分:0)

添加了option.contentType,

      //Assign selected students
    $('#AssignButton').button().click(function () {
        var $selectedRows = $('#NotAllotedStudentsGrid').jtable('selectedRows');
        var selectedRowsList = [];
        var i = 0;
        $selectedRows.each(function () {
            var record = $(this).data('record');
            selectedRowsList[i] = record.UserNo;
            i++;
        });
        var LimitQuestionCount = $("#LimitQuestionCount").val();
        if (selectedRowsList.length > 0) {
            var options = {};
            options.type = "POST";
            options.url = "/Dashboard/AllotQuestionSet/";
            options.data = JSON.stringify({ selectedStudents: selectedRowsList, model: { Effective_date: $("#Effectivedate").val(), ExpiryDate: $("#duedate").val(), LimitQuestionCount: $("#LimitQuestionCount").val() } });
            options.dataType = "json";
            options.contentType = "application/json";
            $.ajax(options);
            alert("ajaxCall");
           // window.location.href = "/Account/ApplInfo/";
        }
    });

已验证。给出完美的结果。

相关问题