我遇到了我的代碼問題。我試圖通過ID 在我的表中選擇行任何幫助真的很感激它。謝謝。不能將類型'...'隱式轉換爲'System.Collections.Generic.IList <...>'。存在明確的轉換(您是否缺少演員?)
public FileStreamResult GetPdf(int? id)
{
IList<Requisition> all = new List<Requisition>();
using (ClinlabEntities dc = new ClinlabEntities())
{
all = dc.Requisitions.ToList().First(ReqId => ReqId.ReqId == id);
}
WebGrid grid = new WebGrid(source: all, canPage: false, canSort: false);
string gridHtml = grid.GetHtml(
columns: grid.Columns(
grid.Column("FirstName", ""),
grid.Column("LastName", " "),
//grid.Column("AccountNo", ""),
grid.Column("Address", ""),
grid.Column("City", ""),
grid.Column("State", ""),
grid.Column("Zip", "")
)).ToString();
string exportData = String.Format("<html><head>{1}</head><body>{1}</body></html>", "<style>table(border-spacing:10px; border-collapse:seperate;)</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.LETTER, 15, 0, 0, -15);
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.UTF7);
document.Close();
output.Position = 0;
return new FileStreamResult(output, "Application/Pdf");
}
}
}
}
你有額外的'}}'在你的代碼也一定要仔細檢查代碼格式在.cs文件以及 – MethodMan