如何使用jquery从网格中显示搜索结果?

时间:2015-01-09 06:29:15

标签: c# jquery asp.net-mvc razor

我喜欢我的jquery,

$(document).ready(function () {
$('#NotAllotedStudentsGrid').jtable({
        title: 'Allot to Students below',
        paging: true,
        pageSize: 5,
        sorting: true,
        defaultSorting: 'Name ASC',
        selecting: true, //Enable selecting
        multiselect: true, //Allow multiple selecting
        selectingCheckboxes: true, //Show checkbo.xes on first column
        actions: {
            listAction: '@Url.Action("NotAllotedStudentsList")',
            //deleteAction: '@Url.Action("DeleteStudent")',
            //updateAction: '@Url.Action("UpdateStudent")',
            //createAction: '@Url.Action("CreateStudent")'
        },
        fields: {
            UserNo: {
                key: true,
                create: false,
                edit: false,
                list: false
            },
            Name: {
                title: 'Name',
                width: '15%'
            },
            Batch: {
                title: 'Batch',
            },
            EmailAddress: {
                title: 'Email address',
            },
            ContactNo: {
                title: 'Contact No',
                type: 'textarea',
            }
        }
    });

    //Load student list from server
    $('#NotAllotedStudentsGrid').jtable('load'); 

     $('#SearchFor').button().click(function () {
        var SearchForValue = $("#NotAllotedStudentsList").val();
        var StudentInputTypeValue = $("#InputType").val();
        var options = {};
            options.type = "POST";
            options.url = "/Dashboard/NotAllotedStudentsList/";
            options.data = JSON.stringify({ model: { SearchFor: SearchForValue, StudentInputType:                  StudentInputTypeValue } });
            options.dataType = "json";
            options.contentType = "application/json";
            $.ajax(options);![enter image description here][1]
    });

我有我的控制器,

    public ActionResult NotAllotedStudentsList(AllotQuestionSet model,int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
    {
        List<TutorStudentsGridModel> tutorStudentsGridModelList = new List<TutorStudentsGridModel>();
        User userDetails = _sessionHelper.Get<User>(KrackemSessionConstants.UserDetails);
        StudentResponse studentListResponse = new StudentResponse();
        int questionSetNo = Int32.Parse(_sessionHelper.Get<string>(KrackemSessionConstants.QuestionSetNo));
       if (model.SearchFor == null)
        {
            StudentRequest studentRequest = new StudentRequest
            {
                TutorUserNo = userDetails.UserNo,
                QuestionSetNo = questionSetNo
            };
             studentListResponse = _questionSetServiceHelper.GetNotAllottedStudentsByTutorNo(studentRequest);
         }
        //Get Not Allotted Students By Name
        if (model.SearchFor != null && model.StudentInputType == StudentInputType.Name)
        {
            StudentRequest studentRequest = new StudentRequest
            {
                TutorUserNo = userDetails.UserNo,
                QuestionSetNo = questionSetNo,
                InputString = model.SearchFor
            };
             studentListResponse = _questionSetServiceHelper.GetNotAllottedStudentsByName(studentRequest);
        }
               foreach (StudentContract studentDetails in studentListResponse.StudentList)
            {
                TutorStudentsGridModel tutorStudentsGridModel = MappingEngineFactory.GetMappingEngine().Map<StudentContract, TutorStudentsGridModel>(
                    studentDetails);
                tutorStudentsGridModel.Id = studentDetails.UserNo;
                tutorStudentsGridModelList.Add(tutorStudentsGridModel);
            }
        if (jtSorting != null)
            tutorStudentsGridModelList = ControllerHelper.SortList(jtSorting, tutorStudentsGridModelList);
           tutorStudentsGridModelList = jtPageSize > 0 ? tutorStudentsGridModelList.Skip(jtStartIndex).Take(jtPageSize).ToList() : tutorStudentsGridModelList.ToList();
           return Json(new { Result = "OK", Records = tutorStudentsGridModelList, TotalRecordCount = studentListResponse.StudentList.Count() });
    }

最初,在选择&#34; name&#34;之后,带有网格的页面从服务器加载,其中包含字段为i.name ii.batch iii.email iv.contact_no的学生列表。从下拉菜单中输入文本框中的名称,然后单击搜索按钮进行搜索,应显示搜索结果。但它显示旧网格。请告诉我如何使用jquery从网格中显示搜索结果。

0 个答案:

没有答案