I am trying to use Index view is strongly typed to a collection of @model IEnumerable and also using Model.Name (model=>model.OrganisationName in Html helper methods). Both in the same view as per my requirement.
@*@model IEnumerable<LMTLibrary.LMTUsage>*@
@model LMTLibrary.LMTUsage
<td width="25%">
@Html.LabelFor(m => m.Organisation, new { @class = "control-label col-md-2" })
</td>
<td width="25%">
@if (ViewBag.UserRoleId == 1)
{
@Html.DropDownListFor(m => m.Organisation, new SelectList(Model.LMTOrganisationList, "Organisation", "Organisation"), "All",
new { @class = "form-control", @onchange = "javascript:GetBusinessArea(this.value);" })
}
else
{
@Html.DropDownListFor(m => m.Organisation, new SelectList(Model.LMTOrganisationList, "Organisation", "Organisation"),
new { @class = "form-control", @onchange = "javascript:GetBusinessArea(this.value);" })
}
@Html.ValidationMessageFor(m => m.Organisation, "", new { @class = "text-danger" })
</td>
@foreach (var item in (IList<LMTLibrary.LMTUsage>)ViewData.Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.UserId)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Organisation)
</td>
<td>
@Html.DisplayFor(modelItem => item.BusinessArea)
</td>
<td>
@Html.DisplayFor(modelItem => item.Company)
</td>
<td>
@Html.DisplayFor(modelItem => item.RoleName)
</td>
<td>
@Html.ActionLink("Edit", "Edit")
</td>
</tr>
}
Below is my controller code
public ActionResult Index()
{
var LMTAccessRoles = AppSettings.Get<string>("Authorization.LMTAccess");
var LMTAdminRoles = AppSettings.Get<string>("Authorization.LMTAdmin");
ViewBag.LMTAccessRoles = LMTAccessRoles;
ViewBag.LMTAdminRoles = LMTAdminRoles;
if (!AuthorizationLevel.GetSecurityLevels(User).Contains("LMTAdmin"))
return RedirectToAction("Unauthorized");
LMTUsage objLMT = new LMTUsage();
LMTDAL objLMTDAL = new LMTDAL();
List<LMTUsage> _OLLMTUsage = new List<LMTUsage>();
_OLLMTUsage = objLMTDAL.UserRoleCompany_GetAll();
return View(_OLLMTUsage.ToList());
}
Which is giving me error. Kindly help me to resolve the issue.