如何将iqueryable数据绑定到ASP gridview [英] How can I bind the iqueryable data to the ASP gridview
问题描述
我想将IQueryable数据绑定到asp gridview
这是来自控制器页面的代码。请检查
我尝试过:
public IQueryable< ordersview>数据()
{
NorthwindDataContext db = new NorthwindDataContext();
var a = db.OrdersViews;
返回a;
}
在index.cshtml页面中我使用了selectMethod来调用来自控制器的方法。我已经尝试了很多,但我无法实现这一点。
请注意我不需要IEnumerable类型但我需要只需要IQueryable数据来绑定网格。
任何人都可以帮我解决这个问题
提前致谢
i want to bind the IQueryable data to the asp gridview
Here is my code from the controller page. please check it
What I have tried:
public IQueryable<ordersview> Data()
{
NorthwindDataContext db = new NorthwindDataContext();
var a = db.OrdersViews;
return a;
}
And in the index.cshtml page i have used selectMethod to call the method from the controller. I have tried a lot but I can't able to achieve this.
Please note I don't need an IEnumerable type but I need just IQueryable data to bind for the grid.
Anybody please help me on this query
Thanks in advance
推荐答案
所以这是将数据从控制器传递到视图的粗略示例。我创建了一个表示实体的类。然后使用该数据创建表。就像Sitecore提到的那样,MVC与Web Forms不同,因此这个实例中的gridview只是一个表格。
样本实体
So this is a rough example of passing data from your controller to your view. I created a class to represent an entity. Then using that data to create a table. Like Sitecore mentioned, MVC is different then Web Forms so a gridview in this instance is simply a table.
Sample entity
public class MyEntity
{
public string Name {get;set;}
}
控制器操作
Controller Action
public ActionResult Index()
{
IQueryable<MyEntity> model = //your data fetching method here to return iqueryable
return View(model);
}
查看 - Index.cshtml
View - Index.cshtml
@model IEnumerable<MyEntity>
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach(var mye in Model)
{
<tr><td>@mye.Name</td></tr>
}
</tbody>
</table>
<!-- or you can use mvc's WebGrid helper. -->
@{
var grid = new WebGrid(Model);
}
@grid.GetHtml()
有关webgrid帮助器的更多信息,请点击此处是一个看起来很有前途的链接,我相信快速的谷歌搜索也会提供数百个其他有用的链接。
ASP.NET MVC4中的WebGrid [ ^ ]
这篇关于如何将iqueryable数据绑定到ASP gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!