TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
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
; }
Reply
Answers (
2
)
I can't get value of base class field from child class object in c#
how to post data to web api from mvc controller easily.