2013-04-04 98 views
0

我正在開發使用EF的ASP.Net mvc 4應用程序。 這是客戶端/ index.cshtml(添加的ExtJS之前)ASP.NET MVC 4和Ext JS 4 Grid Panel

@model IEnumerable<Proj.Client> 

@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table> 
    <tr> 

     <th> 
      @Html.DisplayNameFor(model => model.Name_Clt) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.LName_Clt) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.Birthday_Clt) 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 

     <td> 
      @Html.DisplayFor(modelItem => item.Name_Clt) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.LName_Clt) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Birthday_Clt) 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "Edit", new { id=item.ID_Client }) | 
      @Html.ActionLink("Details", "Details", new { id=item.ID_Client }) | 
      @Html.ActionLink("Delete", "Delete", new { id=item.ID_Client }) 
     </td> 
    </tr> 
} 

</table> 

我下面我這篇文章,但我不能在上面加載數據。 http://cincolabs.com/2012/04/10/asp-net-mvc-4-ext-js-4-gridpanel/

我創建了另一個ClientController。

public JsonResult GetUsers() 
     { 
      var entities = new Entities(); 
      //What is important is to return the data as JSON. 
      return Json(entities.Clients.ToList(), JsonRequestBehavior.AllowGet); 
     } 

我應該重置這段代碼。

public ActionResult Index() 
     { 
      var db = new Entities(); 
      return View(db.Clients.ToList()); 

     } 

另一個問題:

// Set up a model to use in our Store 
    Ext.define('Client', { 
     extend: 'Ext.data.Model', 
     fields: [ 
     { name: 'First_Name', type: 'string' }, 
     { name: 'Last_Name', type: 'string' }, 
     { name: 'Email', type: 'string' }, 
     { name: 'Date_Created', type: 'date', dateFormat: 'MS'} 
    ] 
    }); 

    var userStore = Ext.create('Ext.data.Store', { 
     model: 'Client', 
     proxy: { 
      type: 'ajax', 
      url: '/Examples/GetUsers', 
      reader: { 
       type: 'json', 
       root: 'users' 
      } 
     }, 
     autoLoad: true 
    }); 

這是什麼意思 「URL: '/例子/ GetUsers',」 !!我應該替換它在我的情況!

+0

工作正常,但無法加載數據。我有空的網格! – ImnotaGeek 2013-04-04 19:02:31

回答

0

你的第一個問題有點含糊。我從來沒有與Ext JS一起工作過,但是從你的發佈代碼,在我看來,它使用GetUsers函數創建它自己的表。您發佈的第一個視圖是一個索引視圖,Visual Studio可以自動創建顯示您的數據。如果您的Ext JS正在創建表格,那麼我建議您用適當的代碼替換索引視圖來調用表格數據。然後,應該將方法GetUsers重命名爲Index。

關於/ Examples/GetUsers的問題應該是保存數據的控制器方法的URL(類似於/ Client/Save)。