简体   繁体   English

在ASP.net MVC v1.0中显示数据集内容的最佳实践是什么?

[英]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字典中,但是不确定如何在“视图”页面中显示它。

You may want to view my answer here . 您可能想在这里查看我的答案。 If you still have questions I'll be glad to do what I can. 如果您还有疑问,我将竭尽所能。

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. 没有服务器端控件,可以让你显示的内容DataSetGridView控件中的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.

相关问题 如何将Asp.Net Identity V2.0降级到V1.0? - How to downgrade Asp.Net Identity V2.0 to V1.0? 在Asp.Net MVC 5中实现多个数据库的最佳实践是什么? - What is the best practice for implementing multiple databases in Asp.Net MVC 5? 浏览器链接与Visual Studio 2015 Update 3中的ASP.NET Core v1.0 - Browser Link with ASP.NET Core v1.0 in Visual Studio 2015 Update 3 在ASP.NET MVC中显示数据的最佳解决方案是什么? - What is the best solution for displaying data in ASP.NET MVC? 在ASP.NET MVC中处理2种不同形式之间的共享数据时,最佳实践是什么? - What is the best practice when handling shared data between 2 different forms in asp.net mvc? 如何在ASP.NET MVC中通过Ajax为表添加排序功能?最佳实践是什么 - How to add sort function for the table via ajax in ASP.NET MVC?What is the best practice ASP.NET MVC应用程序在启动时检查依赖项的最佳实践是什么? - What's the best practice for ASP.NET MVC app to check for dependencies at startup? 使用ASP.NET MVC呈现大量html或文本文件的最佳实践是什么? - What is the best practice for using ASP.NET MVC to render lots of html or text files? 在ASP.net MVC中划分大任务的最佳实践 - Best practice to divide a big task in ASP.net MVC MVC / ASP.Net记录级授权的最佳实践 - MVC / ASP.Net Best Practice for Record-Level Authorization
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM