Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
[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;
           }
       }

C#
public class ApplicationDDL
 {
     public int AppId { get; set; }
     public List<SelectListItem> Applications { get; set; }
 }

Partial View
HTML
@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
@Html.Action("ApplicationDDL")

Please let me know what are the changes has to be made to make this work.
Thanks in advance
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900