1

我在数据库中有这个表,Modules它看起来像 数据库表

为了与数据库交互,我使用实体框架,这就是我所做的

public class SISContext : SoramaCoreContext
    {
        public SISContext()
        {
            if(HttpContext.Current == null)
            {
                Database.SetInitializer<SISContext>(null);
            }
        }
        public DbSet<Module> Modules { get; set; }
    }

我对使用 jtable 知之甚少或一无所知。我刚刚在CodeProject上看到了一些教程

我开始知道我必须通过JsonResult才能jtable工作我的模块模型看起来像这样

 public class Module
    {
        public long Id { get; set; }
        public long ModuleTypeId { get; set; }
        public ModuleType ModuleType { get; set; }
        public string ModuleId { get; set; }
        public PropertyConfiguration PropertyConfiguration { get; set; }
        public DateTime DateEntered { get; set; }
    }

这就是我在 Controller 中尝试做的事情

[HttpPost]
        public JsonResult Index()
        {
            try
            {
                List<Module> modules = _db.Modules.ToList();//Don't even know if this collects all the data from table....Any suggestion how to do it?
                return Json(new { Result = "OK", Records = modules });
            }
            catch (Exception ex)
            {

                return Json(new {Result = "ERROR", Message = ex.Message});
            }

        }

这就是我在我看来试图做的事情,现在我只想通过 jtable 在视图中显示ModuleIdDateEntered作为试用。

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/shared/_BootstrapLayout.basic.cshtml";
}
@section head{
    <link href="@Url.Content("~/Content/jtable.2.2.0/themes/metro/blue/jtable.css")" />
    <script type="text/javascript" src="~/Scripts/jquery-2.0.2.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery-ui-1.10.3.js"></script>
    <script type="text/javascript" src="~/Scripts/jtable/jquery.jtable.js"></script>
}    
<div id="ModuleTable" style="width: 580px; margin: auto;"></div>
<script type="text/javascript">
    $(document).ready(function() {
        $('#ModuleTable').jtable({
            title: 'Module List',
            fields: {
                ModuleId: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                DateEntered: {
                    title: 'Date Entered',
                    Width: '15%'
                }
            }
        });
        $('#ModuleTable').jtable('load');
    });
</script>

我知道我在做什么是错误的,但也许我可以在这里得到一些很好的帮助来开始。

目前我收到一个错误:

HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 
So, basically I want to show the table in in picture in my view using jtable.
4

1 回答 1

0

您没有获得操作标签

例如:-

actions: {
    listAction: '/Health/BasicList',
    deleteAction: '/Health/DeleteBasic',
    updateAction: '/Health/UpdateBasic',
    createAction: '/Health/CreateBasic'
},

把它放在标题和字段之间,在这种情况下, Health 是我的 Controller 而 BasicList 是我的控制器方法或操作方法。

于 2013-08-08T10:56:51.553 回答