2013-06-19 23 views
1

我有这个表的数据库称为Modules它看起来像 Database tableMVC 4:使用JTable中创建表

要使用的数据库我使用实体框架,并在此互动是我做了什么

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; } 
    } 

,这就是我一直试图做在控制器

[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}); 
      } 

     } 

,这就是我想在我看来这样做,现在我只是想显示视图ModuleIdDateEntered通过JTable中作为一试出。

@{ 
    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. 

回答

0

你不给动作标签

如: -

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

把它放在标题和田野之间,在这种情况下健康是我的Controller和BasicList是我的控制器方法或操作方法。