本文介绍了从DataBase MVC和Ajax Json Jtable中搜索记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 几个小时后,我会尝试从数据库中搜索。我编写代码以便在您单击时从数据库中查找数据,但它不起作用。点击之后没有任何改变,我想搜索一下例如John......有人帮我解释这是为什么? MyController.cs 使用 System.Collections.Generic; 使用 System.Data; 使用 System.Data.Entity; 使用 System.Linq; 使用 System.Web; 使用 System.Web.Mvc; 使用 Project_MVC; 命名空间 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 ) { 尝试 { // 从数据库中获取数据 使用( var ls = 新的 mydatabase() ) { Wdata = ls.Procedure_ShowData(name,cityid).ToList< Procedure_ShowData_Result>(); } // 将结果返回到jTable return Json( new {Result = OK,Records = Wdata}); } catch (例外情况) { return Json( new {Result = ERROR,Message = 不好}); } } } } My.cshtml < div > 名称:< 输入 type = text name = name id = 名称 / > CityId:< input type = text name = cityid id = cityid / > < 按钮 type = 提交 id = LoadRecordsButton > 加载记录< / button > < / div > < script > $(' #检查')。jtable({消息:polishMessages,分页: true , // 启用分页 pageSize: 10 ,排序: true , 操作:{ listAction:' @ Url.Action(Check)' },字段:{名称:{ title:' Name', width:' 20px' }, CityId:{ title:' CityId',宽度:' 20px' } } } ); $(' #LoadRecordsButton')。click( function (e){ e.preventDefault(); $(' #Check')。jtable(' load',{名称:$(' #name')。val(), CityId:$( ' #cityId')。val()}); }) ; $(' #LoadRecordsButton')。click(); }); < / script > 解决方案 (' #Check')。jtable({ messages:polishMessages, paging: true , // 启用分页 pageSize: 10 ,排序: true , 操作:{ listAction :' @ Url.Action(Check)' }, 字段:{名称:{ title:' 名称', width:' 20px' }, CityId:{ title:' CityId', width: ' 20px' } } }); ( ' #LoadRecordsButton')。click( function (e){ e.preventDefault(); (' #Check')。jtable(' load',{名称: 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.csusing 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<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> 解决方案 ('#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: 这篇关于从DataBase MVC和Ajax Json Jtable中搜索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 13:59