问题描述
您好,
我正在使用MVC3应用程序,我需要使用MVC网格。
现在因为我不能将我的数据表绑定到MVC网格。 beloow是控制器代码,用于在页面中显示某些数据。它的型号名称为PartyHomeModel。模型中有一个数据表和其他变量。我将从我的数据库中填写以下内容。:
/ *
公共ActionResult PartyHome()
{
DataManager DM = new DataManager();
PartyHomeModel pmodel = new PartyHomeModel();
string SQL =select p。*,来自PARTY_MASTER的u.mines_name p内部联接UNIT_MASTER作为你在p.MINES_CODE = u.ore_mines_code,其中p.PARTY_CODE ='+ Session [user_ID] +'和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]。收件人g();
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 =选择RecordSource,BillNo,RecordNo,convert(varchar(11),RecordDt,106)作为RecordDt,BillStatus,convert(varchar(11),BillDt ,作为BillDt,BillAmt,PayMode,ChequeNo,转换(varchar(11),ChequeDt,106)作为来自Tran_BillStatus的ChequeDt,其中Party_Code ='+ Session [user_ID] +'和Mines_Code ='+ Session [ mines] +';
pmodel.BillDT = DM.GetDataTable(SQL);
返回视图(pmodel);
} * /
........................... .........................................
As你看BillDT是我正在填充的数据表,现在我想在我的Html页面中将它绑定到我的网格。但我面临的问题是,当我将模型pmodel返回到视图时,我能够访问并显示所有数据,但我无法将模型BillDT中的此数据表绑定到我的Gridview。请帮助我通过使用MVC3和剃刀工具显示网格与此类数据绑定的过程。
谢谢
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
这篇关于使用数据表填充MVC Razor中的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!