I am beginner in asp.net mvc3
i want to create a grid view using jquery grid of infragistics grid
but have a problem in view grid is not create corresponding model
model:
using System;using System.Linq;using System.Collections.Generic;public class BankAccount{ public int AccountNumber { get; set; } public string AccountName { get; set; } public DateTime AccountDate { get; set; } public string AccountType { get; set; } public decimal AccountBalance { get; set; }}public class AccountModels{ public static IQueryable<BankAccount> GetAccountList() { List<BankAccount> accountList = new List<BankAccount>(); DateTime date = DateTime.Now; for (int i = 1; i < 1001; i++) { accountList.Add(new BankAccount() { AccountNumber = i, AccountName = "Test" + i.ToString(), AccountDate = date, AccountType = "chk", AccountBalance = 12345678.90M } ); } return accountList.AsQueryable<BankAccount>(); }}
View:
@using Infragistics.Web.Mvc;@using Messmanagement.Models;@{ ViewBag.Title = "MealEntry"; Layout = "~/Views/Shared/_Layout.cshtml";}<h2>MealEntry</h2> @( Html.Infragistics().Grid<BankAccount>() .ID("igGrid1") .Columns(column => { column.For(x => x.AccountNumber).DataType("int").HeaderText("Account Number"); column.For(x => x.AccountName).DataType("string").HeaderText("Account Name"); column.For(x => x.AccountDate).DataType("date").HeaderText("Account Date"); column.For(x => x.AccountType).DataType("string").HeaderText("Account Type"); column.For(x => x.AccountBalance).DataType("number").HeaderText("Account Balance"); }) .Features(features => { features.Paging().PageSize(20).PrevPageLabelText("Previous").NextPageLabelText("NEXT"); features.Sorting().Mode(SortingMode.Single).ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("AccountNumber").AllowSorting(true); }); features.Selection().MouseDragSelect(true).MultipleSelection(true).Mode(SelectionMode.Row); }) .ClientDataSourceType(ClientDataSourceType.JSON) .DataSourceUrl(Url.Action("GetAccountList")) .Width("100%") .Height("350") .LocalSchemaTransform(true) .DataBind() .Render() )
Controller:
public class HomeController : Controller { public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; return View(); } public ActionResult About() { return View(); } [GridDataSourceAction] public ActionResult GetAccountList() { return View(Models.AccountModels.GetAccountList()); } }
any one can help please reply.
Thank you
Hello,
As far as I can see your code seems to be fine. I took your logic, placed it in to an application, and then it compiled and ran for me without any issues. I have attached the sample project I used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.
Please note that my test was performed using version 11.1.20111.2030 in NetAdvantage for jQuery 2011 Vol. 1.
Please let me know if I can provide any further assistance.
Hello, Jason
Thank you for post with attachment.
I can found the problem.
I have not link the related javascript file and css file for iggrid of infragistics.
After include these files the grid was successfully created.
Also I want to create a grid with dynamic columns that comes from database table specific column values. Column values depends on difference table column values.
And successfully create dynamic column grid but faced an error at run time in controller when add new records using iggrid.
@model MessManagement.Models.GridVirtualizationModel@using Infragistics.Web.Mvc;@using MessManagement.Models;@using System.Web;@{ ViewBag.Title = "MealInfo"; Layout = "~/Views/Shared/_Layout.cshtml";}@*<script src="../../Scripts/IG/ig.ui.min.js" type="text/javascript"></script><script type="text/javascript" src='@Url.Content("~/Scripts/Samples/combined/min/ig.ui.min.js")' /><script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script><script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>*@<script type="text/javascript"> $(function () { $('#grdMealInfo').live('iggridupdatingrowadded', function () { var ok = confirm("Are you sure to add new record."); if (ok) { $('#grdMealInfo').igGrid("saveChanges") } }); $('#grdMealInfo').live('iggridupdatingrowdeleted', function (event, ui) { var ok = confirm('Do you want to delete this row'); if (ok) { $("#grdMealInfo").igGrid("saveChanges"); } }); });</script><h2>MealInfo</h2><div> @Html.Infragistics().Grid("grdMealInfo", Model.GridVirtualization)</div>
Model:
public class GridVirtualizationModel { public GridVirtualizationModel() { GridVirtualization = new GridModel(); } public GridModel GridVirtualization { get; set; } }
Dynamic Property Model:
public class MealEntry : DynamicObject { // The inner dictionary. Dictionary<string, object> properties = new Dictionary<string, object>(); // This property returns the number of elements // in the inner dictionary. public int Count { get { return properties.Count; } } // If you try to get a value of a property // not defined in the class, this method is called. public override bool TryGetMember(GetMemberBinder binder, out object result) { //string name = binder.Name.ToLower(); string name = binder.Name; return properties.TryGetValue(name, out result); } // If you try to set a value of a property that is // not defined in the class, this method is called. public override bool TrySetMember(SetMemberBinder binder, object value) { // Converting the property name to lowercase // so that property names become case-insensitive. properties[binder.Name.ToLower()] = value; // You can always add a value to a dictionary, // so this method always returns true. return true; } }
Contriller:
public class MealInfoController : Controller { // // GET: /MealInfo/ public ActionResult MealInfo() { GridVirtualizationModel model = new GridVirtualizationModel(); model.GridVirtualization.DataSourceUrl = Url.Action("BindGridVirtualization"); this.InitializeGridVirtualization(model.GridVirtualization); return View(model); } public JsonResult BindGridVirtualization() { GridVirtualizationModel model = new GridVirtualizationModel(); this.InitializeGridVirtualization(model.GridVirtualization); MMDataModelDataContext _db = new MMDataModelDataContext(); var value = from c in _db.GetTable<tblMemberInfo>() select c; model.GridVirtualization.DataSource = value; return model.GridVirtualization.GetData(); } private void InitializeGridVirtualization(GridModel model) { //model.Height = "500px"; // var updating = new GridUpdating(); updating.EnableAddRow = true; updating.EnableDeleteRow = true; updating.EditMode = GridEditMode.Row; // GridPaging paging = new GridPaging(); paging.PageSize = 12; //updating.ColumnSettings.Add(new ColumnUpdatingSetting() { ColumnKey = "MemId", ReadOnly = true }); updating.ColumnSettings.Add(new ColumnUpdatingSetting() { ColumnKey = "MemId" }); List<string> MemList=GetMembers(); int count = MemList.Count; string[] columns = new string[count]; int n=0; foreach (string str in MemList) { columns[n] = str; n++; } //model.Features = list; for (int i = 0; i < count; i++) { model.Columns.Add(new GridColumn(columns[i], columns[i], "number", "150px")); } "150px")); //model.Columns.Add(new GridColumn("PermanentAddress", "PermanentAddress", "string", "250px")); model.UpdateUrl = "Updating"; model.Features.Add(updating); model.Features.Add(paging); model.AutoGenerateColumns = true; model.Virtualization = true; } public ActionResult Updating() { MMDataModelDataContext _db = new MMDataModelDataContext(); var ds = _db.tblMemberInfos; ViewData["GenerateCompactJSONResponse"] = false; GridModel m = new GridModel(); List<Transaction<MealEntry>> transactions = m.LoadTransactions<MealEntry>(HttpContext.Request.Form["ig_transactions"]); foreach (Transaction<MealEntry> t in transactions) { switch (t.type) { case "row": break; case "newrow": { dynamic ob = t.row; //string str = ob["MemId"].ToString(); string str = (string)ob.MemId; break; } case "deleterow": break; } } return View(); } public List<string> GetMembers() { List<string> mem; using (MMDataModelDataContext _db = new MMDataModelDataContext()) { mem = (from c in _db.GetTable<tblMemberInfo>() where c.Active==true select c.MemberNickName).ToList<string>(); } return mem; } }
run time error occur at under line code line
'does not contain a definition for 'Date'
please replay.
Jahangir
Programmer
Interspeed Solutions Ltd.