2012-09-10 85 views

回答

2

以下是我在@Darin Dimmitrov幫助下完成的工作

public ActionResult Index() 
{ 
    var entity = new BloggingEngineDBEntities(); 
    var result = entity.Users.ToList(); 

    var model = new MyViewModel(); 

    var objArray = new object[result.Count]; 
    int counter = 0; 

    foreach (var item in result) 
    { 
     objArray[counter] = new object[] 
           { 
            item.UserName, 
            item.Password, 
            item.DisplayName, 
            item.Email, 
            item.AllowNotifications, 
            item.ImageFilePath 
           }; 
     counter++; 
    } 

    model.Rows = objArray; 

    return View(model); 
} 

它工作:),希望有人認爲這有用。

5

這是一個完全服務器端不可知的純粹的客戶端網格。 documentation也似乎很自我解釋。我請你穿過它。

一旦你經歷了它,事情會變得非常標準。

你開始,將舉行您的動態數據視圖模型:

public class MyViewModel 
{ 
    public object[] Rows { get; set; } 
} 

那麼控制器養活這個視圖模型到視圖:

public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     var model = new MyViewModel 
     { 
      // This data could of course be dynamic and come from wherever you like it to come 
      Rows = new object[] 
      { 
       new object[] { 1, "a" }, 
       new object[] { 2, "b" }, 
       new object[] { 3, "c" }, 
      } 
     }; 
     return View(model); 
    } 
} 

最後一個觀點:

@model MyViewModel 
@{ 
    Layout = null; 
} 
<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <title>Wijmo grid demo </title> 
</head> 
<body> 
    <table id="mytable"></table> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> 

    <!--Theme--> 
    <link href="http://cdn.wijmo.com/themes/rocket/jquery-wijmo.css" rel="stylesheet" type="text/css" title="rocket-jqueryui" /> 

    <!--Wijmo Widgets CSS--> 
    <link href="http://cdn.wijmo.com/jquery.wijmo-complete.all.2.2.1.min.css" rel="stylesheet" type="text/css" /> 

    <!--Wijmo Widgets JavaScript--> 
    <script src="http://cdn.wijmo.com/jquery.wijmo-open.all.2.2.1.min.js" type="text/javascript"></script> 
    <script src="http://cdn.wijmo.com/jquery.wijmo-complete.all.2.2.1.min.js" type="text/javascript"></script> 

    <script type="text/javascript"> 
     $("#mytable").wijgrid({ 
      data: @Html.Raw(Json.Encode(Model.Rows)) 
     }); 
    </script> 
</body> 
</html> 
+0

謝謝@Darin會嘗試一下,我正在閱讀文檔,但發現它很混亂。 – Yasser