Hello,
I am populating a dropdown values in the master page using partial view .It was working properly in the local syatem ,After publishing the same cade in the IIS i am getting Error
There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'AppId'.
I am sharing the code
[ChildActionOnly]
public ActionResult ApplicationDDL()
{
try
{
var apps = new ApplicationDDL();
List<Application> lstApps = new List<Application>();
lstApps = (List<Application>)Session["Applications"];
if (lstApps.Count > 0)
{
var items = new List<SelectListItem>();
foreach (var item in lstApps)
{
var selectedItem = false;
if (item.Id == Convert.ToInt32(Session["AppId"].ToString()))
{
selectedItem = true;
}
items.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString(), Selected = selectedItem });
}
apps.Applications = items;
}
return PartialView("~/Views/Shared/ApplicationDropDown.cshtml", apps);
}
catch (Exception ex)
{
throw ex;
}
}
public class ApplicationDDL
{
public int AppId { get; set; }
public List<SelectListItem> Applications { get; set; }
}
Partial View
@model UMS.MVC.Controllers.ApplicationDDL
<div id="applicationDropdown">
<div style="float: left; margin-left: 3px; color: white; padding-top: 6px;">
@Html.Label("Application : ")
</div>
<div style="float: left; margin-left: 8px; padding-bottom: 6px; padding-top: 6px;">
@Html.DropDownListFor(m => m.AppId, Model.Applications, new { @class = "appDDL", @id = "appDDL"})
</div>
calling this dropdown in the layout page
@Html.Action("ApplicationDDL")
Please let me know what are the changes has to be made to make this work.
Thanks in advance