public IEnumerable<SelectListItem> GetYesNoDropDown(object selectedValue)
{
return new List<SelectListItem>
{
new SelectListItem{ Text="Yes", Value = "Y", Selected = "Y" == selectedValue.ToString()},
new SelectListItem{ Text="No", Value = "N", Selected = "N" == selectedValue.ToString()},
};
}
var list = GetYesNoDropDown(user.IsActive);
ViewData["yesnoList"] = list;
@Html.DropDownList("yesnoDropDown", ViewData["yesnoList"] as List<SelectListItem>, new { @class = "form-control" })
when I do
I have model property IsActive How can I point to my model property from DropDownList,
when I do
@Html.DropDownList(model=>model.IsActive,"yesnoDropDown", ViewData["yesnoList"] as List<SelectListItem>, new { @class = "form-control" })
intellisense is not showing my property IsActive and it is giving me error:
<div>Error CS1660 Cannot convert lambda expression to type 'string' because it is not a delegate type why?</div> <div>I want to send selected property value IsActive to the server.</div>
IsActive is property in @model NicUserManagement.Models.ViewModel.User_TableVm it is not binding to model=>model.IsActive property. It is not even showing by IDE IntelliSense . I want to bind that property but in current context it is not doing that
public IEnumerable<SelectListItem> GetYesNoDropDown(object selectedValue) { return new List<SelectListItem> { new SelectListItem{ Text="Yes", Value = "Y", Selected = "Y" == selectedValue.ToString()}, new SelectListItem{ Text="No", Value = "N", Selected = "N" == selectedValue.ToString()}, }; } void ActionResult Edit(int id){ var user = DBEntities.User_Table.FirstOrDefault(x => x.Id == Id); var list = GetYesNoDropDown(user.IsActive); ViewData["yesnoList"] = list; } [HttpPost] void AcitionResult Edit(User_TableVm uv){
}
@Html.DropDownList("yesnoDropDown", ViewData["yesnoList"] as List<SelectListItem>, new { @class = "form-control" })
when i write above code it is showing me dropdown when I press send button I want to bind property to the model. But problem is I am not able to bind property from my model
When I bind model to by viewmodel it gives me error also I can't able to receive value from GetYesNoDropDown method .
When i Press send button GetYesNoDropDown method Value property to IsActive property.
@Html.DropDownList(model=>model.IsActive,"yesnoDropDown", ViewData["yesnoList"] as List<SelectListItem>, new { @class = "form-control" })
Member
11 Points
24 Posts
Dropdown list is not sending value "Y" or "N" why?
May 21, 2020 01:35 PM|jameslovemicrosoft|LINK
when I do
I have model property IsActive How can I point to my model property from DropDownList,
when I do
intellisense is not showing my property IsActive and it is giving me error:
<div>Error CS1660 Cannot convert lambda expression to type 'string' because it is not a delegate type why?</div> <div>I want to send selected property value IsActive to the server.</div>All-Star
58204 Points
15661 Posts
Re: Dropdown list is not sending value "Y" or "N" why?
May 21, 2020 02:24 PM|bruce (sqlwork.com)|LINK
Only the DropdownListFor accepts a delegate. Try
Member
11 Points
24 Posts
Re: Dropdown list is not sending value "Y" or "N" why?
May 21, 2020 02:51 PM|jameslovemicrosoft|LINK
Hello bruce,
IsActive is property in @model NicUserManagement.Models.ViewModel.User_TableVm it is not binding to model=>model.IsActive property. It is not even showing by IDE IntelliSense . I want to bind that property but in current context it is not doing that
when i write above code it is showing me dropdown when I press send button I want to bind property to the model. But problem is I am not able to bind property from my model
When I bind model to by viewmodel it gives me error also I can't able to receive value from GetYesNoDropDown method .
When i Press send button GetYesNoDropDown method Value property to IsActive property.
All-Star
58204 Points
15661 Posts
Re: Dropdown list is not sending value "Y" or "N" why?
May 21, 2020 03:16 PM|bruce (sqlwork.com)|LINK
as I said, DropDownList does not take a lambda (delegate), it want the string name of the model property. if the property is IsActive, then its:
if you want intellisense, then use the DropDownListFor which was designed for intelligence (it call the above);
Member
11 Points
24 Posts
Re: Dropdown list is not sending value "Y" or "N" why?
May 21, 2020 03:23 PM|jameslovemicrosoft|LINK
Thanks bruce for your time.