Hi i am using partial view in index.cshtml page. and partial view contains one dropdownlist which is bind dynamically from database.
I don't want to use viewbag or viewdata for binding this dropdownlist.
In Controller
// GET: Reporting/Home
public ActionResult Index()
{
var view = View();
return view;
}
public ActionResult _ReportingMenu()
{
var DashboardList = GetAllDashboards();
return View(DashboardList);
}
public IEnumerable<DashboardDefinition> GetAllDashboards()
{
return _reortDefinitionService.GetAllDashboards();
}
In index.cshtml
@model IEnumerable<Portal.Domain.ReportingModule.ReportDefinition.DashboardDefinition>
@{
ViewBag.Title = "Reporting";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Reporting View</h2>
@Html.ActionLink("Add new Chart", "Create", "Chart", new { area = "Reporting" }, null)
@Html.Partial("_ReportingMenu")
In Partialview
@model Portal.Domain.ReportingModule.ReportDefinition.DashboardDefinition
<div class="nav navbar navbar-default navbar-no-margin submenu">
@Html.DropDownList("Mobiledropdown1",IEnumerable<Model.DashboardName>)
<a id="SubMenuIntegratorNew" class="btn btn-default submenu-item" href="#">
<i class="fa fa-file-o fa-lg"></i>
<span class="submenu-item-text">New</span>
</a>
<a id="SubMenuIntegratorSave" class="btn btn-default submenu-item" href="#">
<i class="fa fa-floppy-o fa-lg"></i>
<span class="submenu-item-text">Save</span>
</a>
<a id="SubMenuIntegratorSaveAs" class="btn btn-default submenu-item" href="#">
<i class="fa fa-files-o fa-lg"></i>
<span class="submenu-item-text">Save As</span>
</a>
<a id="SubMenuIntegratorAddChart" class="btn btn-default submenu-item" href="#">
<i class="fa fa-picture-o fa-lg"></i>
<span class="submenu-item-text">Add Chart</span>
</a>
</div>
but i get an error of null model.
I don't know how to implement in partial view
DropDownListFor()isIEnumerable<SelectListItem>(either that or you need aViewBagproperty namedMobiledropdown1which isIEnumerable<SelectListItem>) What is your model (do you really have a property namedMobiledropdown1) And why are your not using the strongly typed helper? And show the full details of the exception.