2013-06-19 21 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是我的控制器方法或操作方法。