suman goud

suman goud

  • NA
  • 176
  • 51k

How insert selected drop down value in database

Aug 5 2016 8:33 AM
am binding values to drop down from database, but when am inserting selected value again in db am getting error 'object ref not set to instance of obj'
 
 my model
public class ReceiptsViewModel
{
public String Branch { get; set; }
public string Currency { get; set; } 
public SelectList CustomerListModel { get; set; }
public SelectList AccountListModel { get; set; }
}
 
 
controller
public ActionResult Index()
{
ReceiptsViewModel objCustomermodel = new ReceiptsViewModel();
TestDemoEntities objentity = new TestDemoEntities();
List<MasterNode> objCus = (objentity.MasterNodes.Where(x => x.Type == "Master")).ToList();
MasterNode objCustomer = new MasterNode();
objCustomer.Name = "Select";
objCustomer.EmpID = 0;
objCus.Insert(0, objCustomer);
SelectList CustomerList = new SelectList(objCus, "EmpID", "Name");
objCustomermodel.CustomerListModel = CustomerList;
return View(objCustomermodel);
}
 
view
 
@Html.DropDownListFor(u => u.Account, Model.AccountListModel, new { @style = "width:150px;height:22px;", @id = "ddlAccount" }) 
 
am getting error here
'

Object reference not set to an instance of an object.

 
how to insert selected value in database 
 

Answers (2)