简体   繁体   English

ASP.NET MVC 使用 WCF 从 SQL Server 获取数据:如何在控制器中放置临时数据存储

[英]ASP.NET MVC get data from SQL Server with WCF : how to put temporary data store in controller

I want to do grid, I get 1000 rows of data from SQL Server with WCF, then I put grid 10 data in view in first after use scroll and get 10-20 data from controller in two after use scroll and get 20-30 data from controller in three..... use scroll and get 990-1000 data from controller.我想做网格,我使用 WCF 从 SQL Server 获取 1000 行数据,然后在使用滚动后首先将网格 10 数据放入视图中,并在使用滚动后从控制器中获取 10-20 数据并获取 20-30 数据从控制器中的三个..... 使用滚动并从控制器获取 990-1000 数据。 But I must go SQL Server with WCF only one time for 1000 rows of data (I cannot go to SQL Server all time (example 0-10,10-20,20-30)) and I put 10 data grid in view, problem is 990 rows of data in controller.但是对于 1000 行数据,我必须只使用 WCF一次使用 SQL Server(我不能一直使用 SQL Server(例如 0-10,10-20,20-30))并且我将 10 个数据网格放在视图中,问题是控制器中的 990 行数据。

How to keep 990 rows of data in the controller ?如何在控制器中保留 990 行数据?

You can make use of Caching for this您可以为此使用Caching

Either use the System.Web.Caching要么使用System.Web.Caching

Or use MemoryCache或者使用内存缓存

Depending on you setup, you might also be able to use OutputCache根据您的设置,您可能还可以使用OutputCache

    [OutputCache(Duration=10, VaryByParam="none")]
    public ActionResult Result()
    {
        return Data();
    }

See http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/improving-performance-with-output-caching-cs for more around this.有关更多信息,请参阅http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/improving-performance-with-output-caching-cs

your description is quite confusing.你的描述相当混乱。 Sorry if I misunderstood your requirement.对不起,如果我误解了你的要求。

If it involve over 1000+ of data, session is not a good option especially if your program involve other usage of session.如果它涉及超过 1000 多个数据,则 session 不是一个好的选择,特别是如果您的程序涉及 session 的其他用法。

Since you are using MVC, you can take advantage of new option such as ViewData and TempData.由于您使用的是 MVC,您可以利用新选项,例如 ViewData 和 TempData。 You can read more about it here .您可以在此处阅读更多相关信息。

I used TempData before and it can process large amount of data (I did not count how much it was, but consider quite huge) so it should be a much better option than session.我之前用过 TempData ,它可以处理大量数据(我没有计算它有多少,但认为相当大)所以它应该是一个比 session 更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC从MS SQL Server获取数据 - Asp.net mvc get data from ms sql server 如何在同一项目中的ASP.NET MVC控制器中从ASP.NET Web API获取数据 - How get data from asp.net web api in asp.net mvc controller in the same project 使用ASP.NET MVC从记事本文件中读取数据并存储到SQL Server中的表中 - Read Data from Notepad File and Store into a Table in SQL Server using ASP.NET MVC 如何在asp.net mvc控制器中获取发布的表单数据 - how to get posted form data in asp.net mvc controller 如何在ASP.NET MVC控制器中获取发布JSON数据 - How to get the post json data in asp.net mvc controller 如何将数据从 Controller 传递到 ASP.NET MVC 中的 WebForm? - How to pass data from Controller to WebForm in ASP.NET MVC? 如何将数据从控制器传递到 ASP.NET MVC 中查看 - How to to pass data from controller to view in ASP.NET MVC 如何从ASP.Net MVC控制器发布JSON数据? - How to post JSON data from ASP.Net MVC controller? 如何将数据从Select2选项/值(标签)获取到ASP.NET MVC中的控制器? - How do I get the data from a Select2 options/value (tags) to the controller in asp.net mvc? 如何从html表单获取数据并将其存储在ASP.Net MVC视图中的ac#变量中 - how to get data from html form and store it in a c# variable in ASP.Net MVC view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM