venkat

venkat

  • NA
  • 138
  • 51.4k

dynamic data is getting null while click second page

Oct 17 2017 7:48 AM
Hi All,
 
I wrote code for showing dynamic data. i am able to getdata but problem is while clicking second page everything is gone . please any one help me. 
below is my code.
model:
public DataTable GetreferenceDT()
{
ValidatorServiceClient client = new ValidatorServiceClient();
ReferenceTableDataSet = new ReferenceTablesDetails();
if (!string.IsNullOrEmpty(referanceData))
{
ReferenceTableDataSet = client.GetReferenceDatabytableId(referanceData);
}
return ReferenceTableDataSet.ColumnInformation.Tables[1];
}
public List<dynamic> ConvertDtToList(DataTable dt)
{
var data = new List<dynamic>();
foreach (var item in dt.AsEnumerable())
{
// Expando objects are IDictionary<string, object>
IDictionary<string, object> dn = new ExpandoObject();
foreach (var column in dt.Columns.Cast<DataColumn>())
{
dn[column.ColumnName] = item[column];
}
data.Add(dn);
}
return data;
}
Controller:
 
[HttpPost]
public ActionResult ReferenceData(ReferanceDataModel referenceModelValue)
{
DataTable dt = referenceModelValue.GetreferenceDT();
referenceModelValue.ColumnNames = new List<System.Web.Helpers.WebGridColumn>();
foreach (DataColumn col in dt.Columns)
{
referenceModelValue.ColumnNames.Add(new System.Web.Helpers.WebGridColumn()
{
ColumnName = col.ColumnName,
Header = col.ColumnName
});
}
referenceModelValue.TableColumnValues = new List<dynamic>();
referenceModelValue.TableColumnValues = referenceModelValue.ConvertDtToList(dt);
return View(referenceModelValue);
}
 
View:
 
@{
List<dynamic> dynamicValues = new List<dynamic>();
dynamicValues = Model.TableColumnValues;
if (dynamicValues != null)
{
var grid = new WebGrid(dynamicValues);
<div id="gridContent">
@grid.GetHtml(
tableStyle: "webGrid",
fillEmptyRows: false,
alternatingRowStyle: "alt",
headerStyle: "header",
emptyRowCellValue: null,
columns: Model.ColumnNames
)
</div>
}
}
 
UI: 
 
while clicking 2 page iam not getting any data. that mean 
List<dynamic> dynamicValues = new List<dynamic>();
dynamicValues = Model.TableColumnValues;
if (dynamicValues != null)
{
Model.TableColumnValues is showing null. i am not able to fix this issue. please help any one on this.