При получении списка отображается следующее необработанное исключение пользователя.
System.Data.Entity.Core.EntityCommandExecutionException: «Средство чтения данных несовместимо с указанным« EE_PlacementCellModel.PlacedCandidateList ». Элемент типа «DriveDate» не имеет соответствующего столбца в считывателе данных с тем же именем. '
Исключение показано в последнем коде возврата: Placement.Context.cs
public virtual ObjectResult<PlacedCandidateList> PlacedCandidateList(Nullable<int> mstID, Nullable<int> cmpID)
{
var mstIDParameter = mstID.HasValue ?
new ObjectParameter("MstID", mstID) :
new ObjectParameter("MstID", typeof(int));
var cmpIDParameter = cmpID.HasValue ?
new ObjectParameter("CmpID", cmpID) :
new ObjectParameter("CmpID", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<PlacedCandidateList>("PlacedCandidateList", mstIDParameter, cmpIDParameter);
}
Другие соответствующие коды приведены ниже: ReportController.cs
public ActionResult PlacedCandidateList(string MstID, string CmpID)
{
int driveID = 0;
int companyID = 0;
if (MstID != "")
driveID = Convert.ToInt32(MstID);
if (CmpID != "")
companyID = Convert.ToInt32(CmpID);
ViewBag.Status = Db.Status.ToList();
var List = Db.PlacedCandidateList(driveID, companyID);
return Json(List.ToList(), JsonRequestBehavior.AllowGet);
}
public ActionResult PlacedCandidate()
{
ViewBag.Drive = Db.DriveMasters.Where(a => a.Isdeleted == false).ToList();
ViewBag.Company = Db.Companies.Where(a => a.Isdeleted == false).ToList();
return View();
}
[HttpPost]
public ActionResult PlacedCandidate(CandidateList candidate)
{
ViewBag.Drive = Db.DriveMasters.Where(a => a.Isdeleted == false).ToList();
ViewBag.Company = Db.Companies.Where(a => a.Isdeleted == false).ToList();
if (candidate.CompanyID == null)
candidate.CompanyID = 0;
if (candidate.DriveMasterID == null)
candidate.DriveMasterID=0;
List<PlacedCandidateList> CSL = new List<PlacedCandidateList>();
CSL = Db.PlacedCandidateList(candidate.DriveMasterID, candidate.CompanyID).ToList();
WebGrid grid = new WebGrid(source: CSL, canPage: false, canSort: false);
string gridhtml = grid.GetHtml(
columns: grid.Columns(
grid.Column("SerailNo", "Serail No"),
grid.Column("StudentName", "Student Name"),
grid.Column("DriveName", "Drive Name"),
//grid.Column("DriveDate", "Drive Date"),
grid.Column("CompanyName", "Company Name"),
grid.Column("PositionName", "Position Name")
)).ToString();
string exportdata = string.Format("<html><head>{0}</head><body>{1}</body></html>", "<style>table {border-collapse: collapse; width: 100%; border: 1px solid #ddd;} th, td {text-align: left;padding: 8px; width:100px; border-bottom: 1px solid #ddd;} tr:nth-child(even){background-color: #f2f2f2} th {background-color: #4CAF50; color: white;} </style>", gridhtml);
var bytes = System.Text.Encoding.UTF8.GetBytes(exportdata);
using (var input = new MemoryStream(bytes))
{
var output = new MemoryStream();
var document = new iTextSharp.text.Document(PageSize.A4, 50, 50, 50, 50);
var writer = PdfWriter.GetInstance(document, output);
writer.CloseStream = false;
document.Open();
var xmlworker = iTextSharp.tool.xml.XMLWorkerHelper.GetInstance();
xmlworker.ParseXHtml(writer, document, input, System.Text.Encoding.UTF8);
document.AddTitle("Placed Candidates");
document.AddCreationDate();
document.Close();
output.Position = 0;
return new FileStreamResult(output, "application/pdf");
}
}
PlacedCandidateList .cs
/------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PlacementCell.Models
{
using System;
public partial class PlacedCandidateList
{
public Nullable<long> SerailNo { get; set; }
public int CandidatesListID { get; set; }
public string CompanyName { get; set; }
public string PositionName { get; set; }
public string StudentName { get; set; }
public string DriveName { get; set; }
public string Status { get; set; }
public int StatusID { get; set; }
public string DriveDate { get; set; }
}
}
PlacedCandidate.cs html
@model PlacementCell.Models.CandidateList
@{
ViewBag.Title = "Placed Candidate";
}
@using (Html.BeginForm("PlacedCandidate", "Report", FormMethod.Post, new { enctype = "multipart/form-data", name = "candidate", id = "candidate" }))
{
<div class="callout bg-gray-light">
<div class="row">
<div class="col-xs-2 col-md-1"><a href="#" onclick="document.getElementById('candidate').submit();"><div class="btn btn-app btn-twitter"><i class="glyphicon glyphicon-print"></i>Print</div></a></div>
</div>
</div>
<section class="content-header">
<h1>
Placed Candidates
<small>Report</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-list-alt"></i> Report</a></li>
<li class="active"><i class="fa fa-circle-o"></i> Placed Candidates</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="box">
<div class="box-body">
<br />
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-6"> Placement Drive</div>
<div class="col-md-6">
@Html.DropDownListFor(model => model.DriveMasterID, new SelectList(ViewBag.Drive, "DriveMasterID", "DriveName"), "Select Drive", new { @class = "form-control", @Onchange = " GetVariables();" })
</div>
</div>
<div class="form-group">
<div class="col-md-6">Company</div>
<div class="col-md-6">
@Html.DropDownListFor(model => model.CompanyID, new SelectList(ViewBag.Company, "CompanyID", "CompanyName"), "Select Company", new { @class = "form-control", @Onchange = " GetVariables();" })
</div>
</div>
<div class="form-group">
<div class="col-md-6"></div>
<div class="col-md-6">
<a href="#" onclick="GetList();" class="btn btn-primary">Find</a>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<table class="table table-bordered table-hover dataTable">
<thead>
<tr>
<th>
<input type="checkbox" class="checkbox" />All
</th>
<th>
Sl.
</th>
<th>
Company Name
</th>
<th>
Drive Name
</th>
<th>
Drive Date
</th>
<th>
Position Name
</th>
<th>
Student Name
</th>
<th>
</th>
</tr>
</thead>
<tbody id="drive">
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
}
@section scripts
{
<script type="text/javascript">
function GetList() {
var MstID = document.getElementById("DriveMasterID").value;
var CmpID = document.getElementById("CompanyID").value;
//alert(MstID);
$.ajax({
url: '/Report/PlacedCandidateList',
type: "GET",
data: { MstID: MstID, CmpID: CmpID },
dataType: "JSON",
success: function (List) {
//alert("ffffg");
$("#drive").html(""); // clear before appending new list
//alert("ff");
var k = 10;
var j = 1;
$.each(List, function (i, vari) {
var Qun = "arr" + k;
var ErrorQun = "arre" + k;
var chbbx = '<tr id="checkboxes"><td><input type="checkbox" name="CandidatesListID" id=' + k + ' class="checkbox" value=" ' + vari.CandidatesListID + '" checked="checked" disabled="disabled" /></td><td> ' + j + ' </td><td> ' + vari.CompanyName + ' </td><td> ' + vari.DriveName + ' </td><td> ' + vari.DriveDate + '</td><td> ' + vari.PositionName + ' </td><td> ' + vari.StudentName + ' </td><td> ' + vari.Status + '</td></tr>';
$("#drive").append(
$(chbbx));
k++;
j++;
//alert(place.Place1);
}
);
},
error: function (List) {
alert("No Data Found");
$("#drive").html("");
}
});
}
</script>
}