I am getting the following exception:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 34: <div>
Line 35: @Html.LabelFor(m => m.accountStatus)
Line 36: (HERE) @Html.DropDownListFor(m => m.accountStatus, Model.accStat)
Line 37: </div>
Line 38: </fieldset>
Following is the model that I am using.
I have created a List property in my model. And I am referencing it in my Html.DropDownListFor helper.
But I am getting exception.
public class OperatorModel
{
[Required]
[Display(Name = "Account ID")]
public string accountID { get; set; }
[Required]
[Display(Name = "Account Name")]
public string accountName { get; set; }
[Required]
[Display(Name = "Password")]
public string password { get; set; }
public List<SelectListItem> accStat
{
get
{
List<SelectListItem> lst = new List<SelectListItem>();
lst.Add(new SelectListItem { Text="ACTIVE", Value="0", Selected=true });
lst.Add(new SelectListItem { Text="DEACTIVATED", Value="1" });
return lst;
}
}
EDIT
Following is my controller code:
public class AdministratorController : Controller
{
//
// GET: /Administrator/
public ActionResult Index()
{
return View();
}
public ActionResult Create()
{
return View();
}
public ActionResult Read()
{
return View();
}
public ActionResult Update()
{
return View();
}
public ActionResult Disable()
{
return View();
}
public ActionResult Enable()
{
return View();
}
}
You have to pass the OperatorModel to the view from your action:
for instance: