Hello Every One i have use this code for get value in drop down list .But i have face issue.This is my code
- public IEnumerable<SelectListItem> GetPlanList()
- {
- var PlanList = _context.PlanMaster.OrderByDescending(x => x.PlanId)
- .Select(x => new SelectListItem()
- {
- Text = x.PlanName,
- Value = x.PlanId.ToString()
- }).ToList(); --- it's me c# code
- return PlanList;
This is my script
- $(document).ready(function () {
- debugger;
- $("#DropDown").change(function () {
- $.get("/AddCoupan/GetPlanList", { PlanId: $("#DropDown").val() }, function (data) {
- $.each(data, function (index, row) {
- $("#DropDown").append("<option value='" + row.planId + "'>" + row.planName + "</option>")
- });
- });
- })
- });
- </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
- public int PlanId { get; set; }
- public IEnumerable<SelectListItem> PlanMaster { get; set; }
- public string PlanName { get; set; }