0

几个小时后,我将尝试从数据库中进行搜索。我写了代码,当你点击时从数据库中查找数据,但它不起作用。单击后没有任何变化,我希望搜索例如“约翰”......有人帮我这是为什么?

我的控制器.cs

using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project_MVC;

namespace Project_MVC.Controllers
{ 
    public class MyController : Controller
    {
        private mydatabase db = new mydatabase();


        [HttpPost]
        public JsonResult CheckData(string name = "",string cityid = "", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {
            try
            {

                //Get data from database
                using (var ls = new mydatabase())
                {
                    Wdata = ls.Procedure_ShowData(name,cityid).ToList<Procedure_ShowData_Result>();
                }



                //Return result to jTable
                return Json(new { Result = "OK", Records = Wdata });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = "No good" });
            }
        }

}
}

我的.cshtml

<div>

        Name: <input type="text" name="name" id="name" />
       CityId: <input type="text" name="cityid" id="cityid" />
        <button type="submit" id="LoadRecordsButton">Load records</button>

</div>
<script>
    $('#Check').jtable({
            messages: polishMessages,
            paging: true, //Enable paging
            pageSize: 10,
            sorting: true,

            actions: {
                listAction: '@Url.Action("Check")'

            },
            fields: {
            Name: {
                    title: 'Name',
                    width: '20px'
                },
                CityId: {
                    title: 'CityId',
                    width: '20px'
                }
            }
        });
 $('#LoadRecordsButton').click(function (e) {
            e.preventDefault();
            $('#Check').jtable('load', {
                Name: $('#name').val(),
                CityId: $('#cityId').val()
            });
        });
        $('#LoadRecordsButton').click();

    });
</script>
4

1 回答 1

0

可能您应该首先将数据发布到您的 CheckData 方法,并且只在 div 中加载数据:

$('#LoadRecordsButton').click(function (e) {
            e.preventDefault();

$post('/MyController/CheckData?name='+$('#name').val()+'&cityid='+$('#cityId').val())
       .always(function()
           {
            $('#Check').jtable('load', {
                Name: $('#name').val(),
                CityId: $('#cityId').val()
             });
            });
        });
于 2013-08-11T13:14:37.470 回答