Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code
MOdel:
XML
public List<IDictionary> GetReports(string strEMPID, int strpresetID)
       {
           SqlConnection conn = new SqlConnection(connStr);
           conn.Open();

           SqlCommand cmd = new SqlCommand("SP_REPORT_PRESET", conn);
           cmd.CommandType = CommandType.StoredProcedure;

           cmd.Parameters.AddWithValue("@strEmpID", strEMPID);
           cmd.Parameters.AddWithValue("@strpresetid", strpresetID);

           DataSet ds = new DataSet();
           SqlDataAdapter adp = new SqlDataAdapter(cmd);
           adp.Fill(ds);
           conn.Close();

           return ConvertToDictionary(ds.Tables[0]); ;
       }


       private List<IDictionary> ConvertToDictionary(DataTable dtObject)
       {
           var columns = dtObject.Columns.Cast<DataColumn>();

           var dictionaryList = dtObject.AsEnumerable()
               .Select(dataRow => columns
                   .Select(column =>
                       new { Column = column.ColumnName, Value = dataRow[column] })
                            .ToDictionary(data => data.Column, data => data.Value)).ToList().ToArray();

           return dictionaryList.ToList<IDictionary>();
       }




Controller:
XML
public ActionResult GetReports(string strEMPID, int strpresetID)
{
    var result=fldHomeDAL.GetReports(strEMPID,strpresetID);
    //List<FLDHomeDetails> lstFLDHome = fldHome.GetFLDReportsList(dsReports);

    return PartialView("_FLDExportReports", result);
}



view:
@using System.Dynamic
@model List<system.collections.idictionary>
@{
Layout = null;
}
@{
var result = new List<dynamic>();

foreach (var emprow in Model)
{
var row = (IDictionary<string,>)new ExpandoObject();
Dictionary<string,> eachEmpRow = (Dictionary<string,>)emprow;

foreach (KeyValuePair<string,> keyValuePair in eachEmpRow)
{
row.Add(keyValuePair);
}
result.Add(row);
}
var gridReport = new WebGrid(result, canSort: true, ajaxUpdateContainerId: "gridReport",
rowsPerPage: 5);
gridReport.Pager(WebGridPagerModes.NextPrevious); ;
}

@if (@Model != null)
{
@gridReport.GetHtml(tableStyle: "webGrid", headerStyle: "head", alternatingRowStyle: "alt");
}
Posted

1 solution

Addin the return success in jquery function where am invoking the action has fixed the problem

function Print() {
       $.ajax({
           type: "POST",
           url: '@Url.Action("GetReports")',
           data: {
               strEMPID: $("#hdnEMPID").val(),
               strpresetID: $('#lstFLDPresets option:selected').val()
           },
           success: function (result) {
               $('#dialog-edit').html(result);
           },
           error: function (ex) {
           }
       });

   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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