I am new to Mvc
I get the following error in the browser window when i used ef to bind data to dropdownlist
(Error):argument null exception was unhandled by user code and value Can't be null
Controller:
var ob = db.UserSelectApprover();
IEnumerable<SelectListItem> items = ob.Select(c => new SelectListItem
{
Value = c.userid.ToString(),
Text = c.firstname + " " + c.lastname}).ToList();
ViewBag.App = items;
View:
i used dropdown list inside table tag
@using (Html.BeginForm("Apply", "Employee", FormMethod.Post, new { @class = "f" }))
{
...
@Html.DropDownListFor(m=>m.Approver, new SelectList(ViewBag.App, "Value", "Text"),"Select Approver", new { @class = "inp1" } )
...
}
I am getting error as
Server Error in '/' Application.
Value cannot be null.
Parameter name: items
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: items
All the fields including selected item from dropdown list was inserted into database despite of the error