[英]What is the best practice for displaying the contents of a DataSet in ASP.net MVC v1.0?
I am long familiar with using the ASP.net GridView
in ASP.net forms to display the contents of DataSet
on a web page. 我很熟悉使用ASP.net表单中的ASP.net GridView
在网页上显示DataSet
的内容。
What is the best practice for displaying the contents of the DataSet
in ASP.net MVC? 什么是显示内容的最佳实践DataSet
在ASP.net MVC? I can add the DataSet
to my DataVew
dictionary in my controller, but I'm unsure of how to display it in the View page. 我可以将DataSet
添加到控制器中的DataVew
字典中,但是不确定如何在“视图”页面中显示它。
DataSets are uncommon for ASP.NET MVC applications. 数据集对于ASP.NET MVC应用程序并不常见。 There are no server side controls that will allow you to display the contents of a DataSet
as the GridView control in WebForms. 没有服务器端控件,可以让你显示的内容DataSet
为GridView控件中的WebForms控制。 So if you are looking for a best practice, I would suggest you put in place some server side processing that will convert your DataSet into an hierarchy of .NET objects that you would pass to a strongly typed view. 因此,如果您正在寻找最佳实践,建议您进行一些服务器端处理,以将DataSet转换为.NET对象的层次结构,然后将其传递给强类型视图。 Of course if this is a new application you wouldn't even bother fetching the data in a DataSet form but you would use an ORM that will directly give you .NET objects. 当然,如果这是一个新的应用程序,则您甚至都不必费心以DataSet形式获取数据,但可以使用直接为您提供.NET对象的ORM。
So once you have the objects you could take a look at the MVCContrib Grid helper . 因此,一旦有了对象,就可以查看MVCContrib Grid帮助器 。 Of course as you are using ASP.NET MVC 1.0 you will have to make sure to download the proper version of MVCContrib
which is compiled against it because the current version is compiled against ASP.NET MVC 2.0. 当然,当您使用ASP.NET MVC 1.0时,必须确保下载针对它编译的MVCContrib
的正确版本,因为当前版本是根据ASP.NET MVC 2.0编译的。
If you are using SQL Server, then for MVC you want to be using Entity Framework. 如果您使用的是SQL Server,则对于MVC,您想使用实体框架。 Since Oracle responded to me with a lame response about Microsoft not giving them specs ( DEVART has been doing Oracle to Entity Framework for years ) 自从Oracle对我没有给出规范的回应me脚地回应了我(多年来DEVART一直在对Entity Framework使用Oracle)
Regardless, if you have a dataset ( use a datatable if you do not need a heavy dataset ) then to make your life easy you will want to convert your dataset to a List (if you are supplied a dataset from say a web service or layer ... Thus something like 无论如何,如果您有数据集(如果不需要繁重的数据集,请使用数据表),那么为了使您的生活更轻松,您将需要将数据集转换为列表(如果从网络服务或图层中获得了数据集) ...这样的东西
public IEnumerable<IClient> GetClient(IClient client)
{
DataSet dataSet = ....
.....
List<IClient> clients = (from c in dataSet.Tables[0].AsEnumerable()
select new Client()
.....
return clients;
}
Then in your controller: IClient client = (IClient)TempData["Client"]; 然后在您的控制器中:IClient client =(IClient)TempData [“ Client”];
// Instantiate and instance of the repository
var repository = new Get_Client_Repository();
// Set a model object to return the dynamic list from repository method call passing in the parameter data
var model = repository.GetClient(client);
// Call the View up passing in the data from the list
return View(model);
Then in your View: 然后在您的视图中:
@model IEnumerable<CISOnlineMVC.DAL.IClient>
@foreach (var item in Model) {
<tr>
<td>
@Html.ActionLink("Select", "ClientDetails", "Cis", new { id = item.ClientId }, null) |
</td>
<td>
@item.LastName
</td>
.......
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.