首页 新闻 赞助 找找看

.net mvc 如何给layUI数据表格绑定数据

0
悬赏园豆:10 [已解决问题] 解决于 2022-10-08 18:14

//数据请求接口
public ActionResult Index()
{

        List<RouterInfo> routerInfo = db.RouterInfo.ToList();
        LayuiJson layuiJson = new LayuiJson();
        layuiJson.code = 0;
        layuiJson.msg = "";
        layuiJson.count = routerInfo.Count;
        layuiJson.data = new List<object>(routerInfo);
        return View(layuiJson);
        
    }

//json格式转换
public class LayuiJson
{
public int code { get; set; }
public string msg { get; set; }
public int count { get; set; }
public List<Object> data { get; set; }
}
//数据表格获取数据
<script>
layui.use('table', function () {
var table = layui.table;
var sortName = "id";
var sortType = "desc";
var pages = 1;
var rows = 10;
//第一个实例
table.render({
elem: '#LAY_table_user'
, height: 500
, url: '/Controllers/AdminLoginConreoller/Index' //数据接口
, page: true
, limit: 20
, type: 'post'
, cols: [[ //表头
, { field: 'id', title: 'ID', sort: true, fixed: true }
, { field: 'Product', title: '1' }
, { field: 'myProduct', title: '2' }
, { field: 'myProduct3', title: '3' }
, { field: 'myProduct4', title: '4' }
]]
});
});
</script>
数据绑定一直显示404,说是要传page limit,实在不知道在哪里可以传值了

耳东59的主页 耳东59 | 初学一级 | 园豆:90
提问于:2022-09-30 14:52
< >
分享
最佳答案
0

路由怎么配置的,贴出来看看

收获园豆:10
顾星河 | 大侠五级 |园豆:7169 | 2022-09-30 15:56

public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "AdminLogin", action = "Login", id = UrlParameter.Optional },
            namespaces: new string[] {"ManagementWeb.Controllers"}
        );
    }
}是这个嘛
耳东59 | 园豆:90 (初学一级) | 2022-09-30 16:01

@耳东59:
你把数据接口里的url改成:/AdminLogin/Index 试试

顾星河 | 园豆:7169 (大侠五级) | 2022-09-30 16:08

@默卿: 这样的话请求结果就变成请求异常,错误提示:parsererror

耳东59 | 园豆:90 (初学一级) | 2022-09-30 16:16

@耳东59: parsererror说明的数据格式不对(检查后端的返回,和前端的设置是否匹配),请求应该是已经进入了后台的。之前的路由404是因为请求地址写得不对。

顾星河 | 园豆:7169 (大侠五级) | 2022-09-30 16:26

@默卿: 对的,我现在就是不知道怎么传那个值,说是有一个page limit值没有传,然后就数据一直没有绑定成功

耳东59 | 园豆:90 (初学一级) | 2022-09-30 16:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册