2013-04-04 99 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)。