0
我收到一個異常,當我試圖顯示viewbag的值。我加入了兩個表格,並使用Linq將這些數據存儲在viewbag中。'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException''object'不包含'intEmployeeId'的定義
這是我的控制器的操作方法
public ActionResult HRSeparationDetails()
{
//List<trnEsSeparationDetail> separationlist = (from list in db.trnEsSeparationDetails
// select list).ToList();
ViewBag.SeparationList = (from list in db.trnEsSeparationDetails
join R in db.mstEsEmpReasonForSeparations
on list.ReasonForSeperationId equals R.intSeperationId
select new
{
intEmployeeId = list.intEmpId,
ReasonForSeparation = R.txtReasonForSeperation,
ResiganationDate = list.dtResignationDate,
RelievingDate = list.dtRequestedRelievingDate,
SeparationRemarks = list.txtRemark
}).ToList();
return View();
}
這是我的ViewPage
@model IEnumerable<EMPApp.Models.trnEsSeparationDetail>
@{
ViewBag.Title = "HRSeparationDetails";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>HRSeparationDetails</h2>
<div>
@if (ViewBag.SeparationList == null)
{
<div style="color:green"><h3>@ViewBag.SeparationerrorMessage</h3></div>
}
else
{
<table class="grid" cellpadding="0" cellspacing="0">
<tr>
<th>
<b>Employee Id</b>
</th>
@*<th>
<b>ReasonForSeparationId</b>
</th>*@
<th>
<b>Reason For Separation</b>
</th>
<th>
<b>Resignation Date</b>
</th>
<th>
<b>Relieving Date</b>
</th>
<th>
<b>Separation Remarks</b>
</th>
</tr>
@foreach (var item in ViewBag.SeparationList)
{
<tr>
<td>
@item.intEmployeeId
@*@{
Session["SeparationEmpId"] = item.intEmpId;
}
@Html.ActionLink(Session["SeparationEmpId"].ToString(), "EmployeeDashboard", "HRAdmin", new { id = @item.intEmpId }, null)*@
</td>
@*<td>
@item.ReasonForSeperationId
</td>*@
<td>
@item.ReasonForSeparation
</td>
<td>
@item.ResiganationDate
</td>
<td>
@item.RelievingDate
</td>
<td>
@item.SeparationRemarks
</td>
</tr>
}
</table>
}
任何幫助將不勝感激。謝謝..
非常感謝先生視圖模型..其工作很好.. – user3273883 2014-10-22 06:29:07
然後我假設你會接受它。你已經提出了12個問題,並沒有接受一個問題,儘管注意到在另外3個工作中對你有用。不是很好的形式! – 2014-10-22 07:50:23
@StephenMuecke正確的先生,我認爲我們應該避免幫助這種類型的用戶。 – Roshan 2014-10-22 19:53:08