Guest User

Guest User

  • Tech Writer
  • 611
  • 127.3k

Get Drop Down Value

Dec 9 2020 7:55 AM
Hello Every One i have use this code for get value in drop down list .But i have face issue.This is my code
  1. public IEnumerable<SelectListItem> GetPlanList()  
  2. {  
  3. var PlanList = _context.PlanMaster.OrderByDescending(x => x.PlanId)  
  4. .Select(x => new SelectListItem()  
  5. {  
  6. Text = x.PlanName,  
  7. Value = x.PlanId.ToString()  
  8. }).ToList(); --- it's me c# code  
  9. return PlanList;  
This is my script
  1. $(document).ready(function () {  
  2. debugger;  
  3. $("#DropDown").change(function () {  
  4. $.get("/AddCoupan/GetPlanList", { PlanId: $("#DropDown").val() }, function (data) {  
  5. $.each(data, function (index, row) {  
  6. $("#DropDown").append("<option value='" + row.planId + "'>" + row.planName + "</option>")  
  7. });  
  8. });  
  9. })  
  10. });  
  11. </script>  
@Html.DropDownListFor(x=>x.PlanId, Model.PlanMaster,"--Select Plan--",new { @class = "form-control", @id = "DropDown", @required = "required" })--But Here I have Face Issue object reference not set to an instance of an object
 
It's view model class
  1. public int PlanId { getset; }  
  2. public IEnumerable<SelectListItem> PlanMaster { getset; }  
  3. public string PlanName { getset; }  

Answers (2)