Click here to Skip to main content
15,065,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
For a few hours I'll try to do search from the database. I wrote the code to find the data from the database when you click, but it does not work. After clicking nothing has changed, and I wish searched for example, "John" ... Someone help me why this is?

MyController.cs
C#
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" });
            }
        }
      
}
}
My.cshtml
HTML
<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>
Posted
Updated 10-Aug-13 10:31am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900