I have a small application that returns SQL Server data to a cshtml page and populates a chart.
But, the code I used does not seem like the best solution and I was wondering if you could take a look at my code and give me an idea of a better way?
My code is below.
Model:
public class LoginHistory{ public Int32 LoginHistoryID { set; get; } public Decimal LoginDuration { set; get; } public string LoginApp { set; get; } public DateTime LoginDateTime { set; get; } public string LoginUser { set; get; } public string LoginLocation { set; get; } public string LoginEnvironment { set; get; }}CSHTML:
@model IEnumerable<AllanTest01.Models.LoginHistory>@{ Layout = null;}<!DOCTYPE html><html><head> <meta name="viewport" content="width=device-width" /> <title>Index</title> <!-- Kendo References --> <link rel="stylesheet" href="~/Content/kendo.common.min.css"> <link rel="stylesheet" href="~/Content/kendo.default.min.css"> <link href="~/Content/kendo.dataviz.min.css" rel="stylesheet" type="text/css" /> <script src="~/Scripts/jquery.min.js"></script> <script src="~/Scripts/kendo.all.min.js"></script> <script src="~/Scripts/kendo.aspnetmvc.min.js"></script></head><body> <div> Login History Charts 01 <br /><br /> filters_here <br /> Date Range: @(Html.Kendo().DateTimePicker().Name("StartDateTime")) - @(Html.Kendo().DateTimePicker().Name("EndDateTime")) <br /><br /> <table style="width:100%;"> <tr> @* loop thru the apps *@ @foreach (var item in Model) { <td> @(Html.Kendo().Chart() .Name(item.LoginApp.ToString().Replace(" ", "_")) .Title(item.LoginApp) .Legend(legend => legend .Position(ChartLegendPosition.Bottom) ) .Series(series => { series.Column(new double[] { 15.7, 16.7, 20, 23.5, 26.6 }).Name("World"); series.Column(new double[] { 67.96, 68.93, 75, 74, 78 }).Name("United States"); }) .CategoryAxis(axis => axis .Categories("2005", "2006", "2007", "2008", "2009") ) .ValueAxis(axis => axis .Numeric().Labels(labels => labels.Format("{0}%")) ) .Tooltip(tooltip => tooltip .Visible(true) .Format("{0}%") ) .HtmlAttributes(new { style = "width:300px;" }) ) </td> } </tr> </table> @foreach (var item in Model){ <p>@item.LoginHistoryID | @item.LoginDuration | @item.LoginApp | @item.LoginDateTime | @item.LoginUser | @item.LoginLocation</p>} </div></body></html>HomeController.cs:
using AllanTest01.Models;using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using System.Linq;using System.Web;using System.Web.Mvc;namespace AllanTest01.Controllers{ public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { var items = GetLoginHistory(); var newItems = (from p in items select new LoginHistory { LoginHistoryID = p.Field<Int32>("LoginHistoryID"), LoginDuration = p.Field<Decimal>("LoginDuration"), LoginApp = p.Field<String>("LoginApp"), LoginDateTime = p.Field<DateTime>("LoginDateTime"), LoginUser = p.Field<String>("LoginUser"), LoginLocation = p.Field<String>("LoginLocation") }).ToList(); return View(newItems); } private List<DataRow> GetLoginHistory() { List<DataRow> list = null; string srtQry = @"Select LoginHistoryID, LoginDuration, LoginApp, LoginDateTime, LoginUser, LoginLocation, LoginEnvironment From LoginHistories"; string connString = "Data Source=.\\sqlexpress;Initial Catalog=AllanTest;Integrated Security=True"; using (SqlConnection conn = new SqlConnection(connString)) { using (SqlCommand objCommand = new SqlCommand(srtQry, conn)) { objCommand.CommandType = CommandType.Text; DataTable dt = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(objCommand); conn.Open(); adp.Fill(dt); if (dt != null) { list = dt.AsEnumerable().ToList(); } } } return list; } }}open: function (e) { // TODO: fikse knapper: // debugger; var content = $(e.sender.content()); content.find(".popup-fieldset-wrapper").append(content.find(".k-button")); content.find(".k-button").wrapAll("<div class='buttons' style='float: right;'/>"); content.find(".k-button.k-grid-update").addClass("save"); content.find(".k-button.k-grid-cancel").addClass("cancel"); e.sender.content(content); //at first i was converting content back to html(), but seems much better when just putting the jQuery object into content. // e.sender.center(); }

I have two issues when running the grid in ie7 and ie8 compatibility mode:
Here’s my config:
#Grids{
width: 100%;
height:400px;
overflow-y: auto;
overflow-x: auto;
border:1px solid #00215C;
}
<div id="Grids">
<div id="gridMoneyOrders" class="hidden"></div>
</div>
var loadMoneyOrderDetailsGrid = function(details){
$("#gridMoneyOrders").show().kendoGrid({
dataSource: {
data: details,
pageSize: 10,
schema: {
model: {
fields: {
FacilityName: { type: "string" },
MoneyOrderID: { type: "string" },
IssueID: { type: "string" },
ClerkID: { type: "string" },
IssueDateTime: { type: "date" },
SaleAmount: { type: "string" },
PaidAmount: { type: "string" },
ProcessDate: { type: "date" },
SerialNumber: { type: "string" }
}
}
}
},
//change: onChange,
selectable: "row",
groupable: false,
sortable: true,
pageable: {
refresh: true,
pageSizes: false
}
,
columns: [ {
field: "FacilityName",
width: 40,
title: "Facility Name"
} , {
field: "MoneyOrderID",
width: 10,
title: "City"
} , {
field: "IssueID",
title: "Issue",
width: 10
}, {
field: "ClerkID",
title: "Clerk",
width: 10
}, {
field: "IssueDateTime",
title: "Issue Date",
width: 20,
format: "{0:MM/dd/yyyy}"
}, {
field: "SaleAmount",
title: "Sale Amount",
format: "{0:$0.00}",
width: 20
}, {
field: "PaidAmount",
title: "Paid Amount",
format: "{0:$0.00}",
width: 20
}, {
field: "ProcessDate",
title: "Process Date",
format: "{0:MM/dd/yyyy}",
width: 20
}, {
field: "SerialNumber",
title: "Serial Number",
width: 20
}
]
});
var grid = $("#gridMoneyOrders").data("kendoGrid");
grid.refresh();
};
<?PHPclass FileObj { public $name = ""; public $type = ""; public $size = "";}?><?include_once("obj.file.php");$path = $_GET["path"];$serverFilePath = "/home/midmosou/public_html/";$filter = "*.*";if(is_dir($serverFilePath . $path)){ foreach (glob($serverFilePath . $path . $filter) as $filename) { $file = new FileObj(); if (is_dir($filename)) { $file->name = basename($filename); $file->type = "d"; $file->size = "0"; } else { $file->name = basename($filename); $file->type = "f"; $file->size = filesize($filename); } $data[] = $file; } $count = count($data); echo "{\"data\":" .json_encode($data). ", \"count\":" . json_encode($count) . "}";}?>{"data":[{"name":"FaceBook.png","type":"f","size":1331},{"name":"School_dance.jpg","type":"f","size":13576},{"name":"bbb-logo.jpg_600.jpg","type":"f","size":38843},{"name":"bbb_96.gif","type":"f","size":1320},{"name":"blogger_logo.jpg","type":"f","size":18175},{"name":"fztp020w_1.jpg","type":"f","size":46205},{"name":"live_sound_mo.jpg","type":"f","size":22116},{"name":"live_sound_system_rental_mo.jpg","type":"f","size":10794},{"name":"search-engine-optimization_102.png","type":"f","size":18850},{"name":"sound-main-mid-mo.jpg","type":"f","size":29101},{"name":"sound_man_1.jpg","type":"f","size":11412}], "count":11}<textarea id="editor1" id="page_body" name="page_body" style="width: 100%; height: 300px;"><? echo $page_body;?></textarea><script> $(document).ready(function() { $("#editor1").kendoEditor({ encoded: false, imageBrowser: { transport: { read: "/includes/kendoui/service/imagebrowser/read.php", destroy: { url: "/includes/kendoui/service/imagebrowser/destroy.php", type: "POST" }, create: { url: "/includes/kendoui/service/imagebrowser/createDirectory.php", type: "POST" }, imageUrl: "/Company_Images/{0}" }, path: "Company_Images/" } }); });</script>@Html.Kendo().TreeView() .Name("treeview") .DragAndDrop(true) .DataTextField("Name") .Events(events => events .DragEnd("Change") .Select("Selected") .Expand("OnExpand") ) .DataSource(dataSource => dataSource .Read(read => read .Action("GetTreeViewData", "Home")) );
public JsonResult GetTreeViewData(int? id, string Type) /* how can I get my type property here? */ { //data is returned from db - excluded for brevity return Json(data, JsonRequestBehavior.AllowGet); }
treeview.dataItem(e.node).Type (with Type being a property in my Json for the Node)