在Razor中有效显示查询结果(Display query results efficiently in Razor)
我用Visual C#和“Razor”选项创建了一个ASP.NET MVC 4 Web应用程序
HomeController.cs
public ActionResult Tasks() { ViewBag.Message = "Tasks"; string selectSql = "select * from Tasks"; string connectionString = @"Data Source=lpc193\adamssqlserver;Database=master;Integrated Security=True;"; DateTime strt; using (var cn = new SqlConnection(connectionString)) using (var cmd = new SqlCommand(selectSql, cn)) { cn.Open(); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { strt = reader.GetDateTime(reader.GetOrdinal("Start")); } } } return View(); }
Tasks.cshtml
@{ ViewBag.Title = "Tasks To Complete"; } These are the tasks from the table <!-- some datagrid object here ?? -->
我有以下SQL Server 2012数据库表布局
我能够很好地查询表格并单独提取每个字段的值。
我想要做的是将DataGridView中的结果集(包含select *查询中的所有字段)显示给用户。 我可以很容易地将每个值放入一个TR TD并将其放入一个字符串中,将它显示在.cshtml一侧......但那并没有真正教会我什么,我怀疑它非常有效。
注意事项找到有关Razor的相关信息并显示查询数据非常困难。 是因为它是新的,和/或是Razor要避免的C#新手?
I've created an ASP.NET MVC 4 Web Application with Visual C# and with the "Razor" option
HomeController.cs
public ActionResult Tasks() { ViewBag.Message = "Tasks"; string selectSql = "select * from Tasks"; string connectionString = @"Data Source=lpc193\adamssqlserver;Database=master;Integrated Security=True;"; DateTime strt; using (var cn = new SqlConnection(connectionString)) using (var cmd = new SqlCommand(selectSql, cn)) { cn.Open(); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { strt = reader.GetDateTime(reader.GetOrdinal("Start")); } } } return View(); }
Tasks.cshtml
@{ ViewBag.Title = "Tasks To Complete"; } These are the tasks from the table <!-- some datagrid object here ?? -->
I have the following SQL Server 2012 database table layout
I'm able to query the table just fine and pull out each field's value individually.
What I want to do is display the result set (with all fields from the select * query) in a DataGridView of sorts to the user. I could easily place each value into a TR TD and plop that into a string, display it on the .cshtml side... but thats doesn't really teach me anything, and I doubt its very efficient.
side note It's extremely difficult to find relevant information regarding Razor and displaying data from a query. Is it because its new, and/or is Razor something to avoid for a C# novice?
原文:https://stackoverflow.com/questions/16593359
满意答案
希望这有帮助。
var app = angular.module('webStatistics', ['ngRoute']); app.config(function($routeProvider){ $routeProvider .when('/stats/views/', {templateUrl: 'home'}) .when('/stats/views/home.html', { controller : 'testController' templateUrl: '/stats/views/home.html' }) .otherwise({redirectTo : '/'}); }); app.controller('testController', function($scope, $http) { $scope.item1 = ''; $scope.item2 = ''; $scope.getData() { if ($scope.item1 && $scope.item2) { var api = '../app/sources/stats/004/' + item1 + '_' + item2 + '.json'; $http.get(api).success(function(data) { $scope.variables = data; }); } }; });
Hope this help.
var app = angular.module('webStatistics', ['ngRoute']); app.config(function($routeProvider){ $routeProvider .when('/stats/views/', {templateUrl: 'home'}) .when('/stats/views/home.html', { controller : 'testController' templateUrl: '/stats/views/home.html' }) .otherwise({redirectTo : '/'}); }); app.controller('testController', function($scope, $http) { $scope.item1 = ''; $scope.item2 = ''; $scope.getData() { if ($scope.item1 && $scope.item2) { var api = '../app/sources/stats/004/' + item1 + '_' + item2 + '.json'; $http.get(api).success(function(data) { $scope.variables = data; }); } }; });
相关问答
更多如何在Javascript / Angularjs中检测用户来自哪里的URL?(How do I detect the url of where the user is coming from in Javascript/Angularjs?)
Angularjs应用程序没有将个人用户的ID传递给url(Angularjs app not passing id of individual user to url)
根据条件授予用户访问URL的权限(Angularjs)(Give user access to URL based on condition (Angularjs))
AngularJs $资源动态URL(AngularJs $resource dynamic URL)
获取用户来自AngularJS的url(Get the url that a user is coming from AngularJS)
在angularjs中的引荐网址(Referrer url in angularjs)
根据用户选择AngularJS构造URL(Construct URL depending on user choice AngularJS)
AngularJS更新表单有选择菜单选项吗?(AngularJS update form with select menu choice?)
Angularjs - 在不更改URL的情况下更改模板(Angularjs - change templates without changing url)
根据选择跳过问题(Skips questions depending on a choice)
相关文章
更多MongoDB学习 (五):查询操作符(Query Operators).1st
常用HQL(Hibernate Query Language)查询
Solr 使用自定义 Query Parser
Solr 使用自定义 Query Parser
solr学习笔记二-------solr query查询的参数
solr delete query
solr delete query
Mysql错误:Ignoring query to other database解决方法
solr 分页查询与高亮显示
Solr的一些查询参数
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!