Click here to Skip to main content
15,895,142 members

filling a Grid in MVC Razor using datatable

mrbonny7 asked:

Open original thread
Hello,
I am working an MVC3 application where I need to make use of the MVC Grid.
Now as I am not abale to bind my datatable with the MVC grid. beloow is the controller code using which I am displaying certain data in the pages. It has a model name PartyHomeModel. There's a datatable in the model along with other variables. I am filling these from my database as given below.:-
/*
public ActionResult PartyHome()
{
DataManager DM = new DataManager();
PartyHomeModel pmodel=new PartyHomeModel();
string SQL = " select p.*,u.mines_name from PARTY_MASTER p inner join UNIT_MASTER as u on p.MINES_CODE=u.ore_mines_code where p.PARTY_CODE='" + Session["user_ID"] + "' and p.MINES_CODE='" + Session["mines"] + "' ";
DataTable DT2 = new DataTable();
DT2 = DM.GetDataTable(SQL);
pmodel.MINES_CODE = DT2.Rows[0]["MINES_CODE"].ToString();
pmodel.PARTY_CODE = DT2.Rows[0]["PARTY_CODE"].ToString();
pmodel.mines_name = DT2.Rows[0]["mines_name"].ToString();
pmodel.PAN = DT2.Rows[0]["PAN"].ToString();
pmodel.PARTY_NAME = DT2.Rows[0]["PARTY_NAME"].ToString();
pmodel.PHONE = DT2.Rows[0]["PHONE"].ToString();
pmodel.REGN_NO = DT2.Rows[0]["REGN_NO"].ToString();
pmodel.EMAIL = DT2.Rows[0]["EMAIL"].ToString();
pmodel.ADDRESS4 = DT2.Rows[0]["ADDRESS4"].ToString();
pmodel.ADDRESS3 = DT2.Rows[0]["ADDRESS3"].ToString();
pmodel.ADDRESS2 = DT2.Rows[0]["ADDRESS2"].ToString();
pmodel.ADDRESS1 = DT2.Rows[0]["ADDRESS1"].ToString();

SQL = " select RecordSource ,BillNo ,RecordNo,convert(varchar(11),RecordDt,106) as RecordDt,BillStatus,convert(varchar(11),BillDt,106) as BillDt,BillAmt,PayMode,ChequeNo,convert(varchar(11),ChequeDt,106) as ChequeDt from Tran_BillStatus where Party_Code='" + Session["user_ID"] + "' and Mines_Code='" + Session["mines"] + "' ";
pmodel.BillDT =DM.GetDataTable(SQL);
return View(pmodel);
}*/

....................................................................
As u see BillDT is the Datatable I am filling up and now i want to bind this to my Grid in my Html page. but the problem that I am facing is that as I am returning the model "pmodel" to the view and I am able to access and display all data but i cannot bind this datatable in the model "BillDT" to my Gridview. Kindly can u help me by showing the process in which a grid is bind with such datatable using MVC3 and razor tools.
Thank you
Tags: C#, Razor, MVC3, Gridview

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900