Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 19, 2012 06:14 AM by Young Yang - MSFT
Member
23 Points
53 Posts
Apr 17, 2012 07:44 AM|LINK
Hi,
this is my ViewModel
public List<VenueDetails> VenuesList { get; set; } public SelectList VenuesMakeList { get { return new SelectList(VenuesList, "PKVenueId", "Name"); } set { } } public int PKEventId { get; set; } public int? FKVenueId { get; set; } public string VenueName { get; set; } public string EventName { get; set; } public string EventDesc { get; set; } public DateTime? StartDateTime { get; set; } public DateTime? EndDateTime { get; set; } public bool? IsActive { get; set; } public string outlook_file { get; set; } public string picture { get; set; } public bool? bookings_closed { get; set; }
And my View is:
<tr> <td width="25%"> IsActive </td> <td> <%:Html.CheckBoxFor(model => model.IsActive.Value)%> </td> </tr>
In my controller:
[HttpPost] public ActionResult CreateEvent(EventsModel eventModel, FormCollection frmValues) { Event evnt = new Event(); evnt.FKVenueId = eventModel.FKVenueId; evnt.EventName = eventModel.EventName; evnt.EventDesc = eventModel.EventDesc; evnt.StartDateTime = eventModel.StartDateTime; evnt.EndDateTime = eventModel.EndDateTime; evnt.is_active = eventModel.IsActive; evnt.bookings_closed = eventModel.bookings_closed; evnt.picture = eventModel.picture; eventsRepository.InsertEvent(evnt); return View("../Events/GetAllEvents", eventsRepository.GetAllEvents()); }
How to pass the value for checkbox from view to controller ?? I am getting it as null value for "IsActive"
How to pass the dropdownlist selecetd value from view to controller?
Thanks...
220 Points
58 Posts
Apr 17, 2012 07:58 AM|LINK
swapnashetti <td> <%:Html.CheckBoxFor(model => model.IsActive.Value)%> </td>
<td>
<%:Html.CheckBoxFor(model => model.IsActive.Value)%>
</td>
.Value is not required -> <%:Html.CheckBoxFor(model => model.IsActive)%>
swapnashetti How to pass the dropdownlist selecetd value from view to controller?
Use @HtmlDropDownListFor()
Thanks,
Ashok
All-Star
21343 Points
1818 Posts
Microsoft
Apr 19, 2012 06:14 AM|LINK
Hi
Pass the FormCollection in your action, like this:
public class MyController { public ActionResult MyAction (FormCollection form) { string value = form["DropDownListName"]; } }
Hope this helpful Regards Young Yang
swapnashetti
Member
23 Points
53 Posts
ViewModel for checkbox and dropdownlist
Apr 17, 2012 07:44 AM|LINK
Hi,
this is my ViewModel
public List<VenueDetails> VenuesList { get; set; } public SelectList VenuesMakeList { get { return new SelectList(VenuesList, "PKVenueId", "Name"); } set { } } public int PKEventId { get; set; } public int? FKVenueId { get; set; } public string VenueName { get; set; } public string EventName { get; set; } public string EventDesc { get; set; } public DateTime? StartDateTime { get; set; } public DateTime? EndDateTime { get; set; } public bool? IsActive { get; set; } public string outlook_file { get; set; } public string picture { get; set; } public bool? bookings_closed { get; set; }And my View is:
<tr> <td width="25%"> IsActive </td> <td> <%:Html.CheckBoxFor(model => model.IsActive.Value)%> </td> </tr>In my controller:
[HttpPost] public ActionResult CreateEvent(EventsModel eventModel, FormCollection frmValues) { Event evnt = new Event(); evnt.FKVenueId = eventModel.FKVenueId; evnt.EventName = eventModel.EventName; evnt.EventDesc = eventModel.EventDesc; evnt.StartDateTime = eventModel.StartDateTime; evnt.EndDateTime = eventModel.EndDateTime; evnt.is_active = eventModel.IsActive; evnt.bookings_closed = eventModel.bookings_closed; evnt.picture = eventModel.picture; eventsRepository.InsertEvent(evnt); return View("../Events/GetAllEvents", eventsRepository.GetAllEvents()); }How to pass the value for checkbox from view to controller ?? I am getting it as null value for "IsActive"
How to pass the dropdownlist selecetd value from view to controller?
Thanks...
ashok4v
Member
220 Points
58 Posts
Re: ViewModel for checkbox and dropdownlist
Apr 17, 2012 07:58 AM|LINK
.Value is not required -> <%:Html.CheckBoxFor(model => model.IsActive)%>
Use @HtmlDropDownListFor()
Thanks,
Ashok
(Don't forget to click "Mark as Answer" on the post(s) that helped you.)
Young Yang -...
All-Star
21343 Points
1818 Posts
Microsoft
Re: ViewModel for checkbox and dropdownlist
Apr 19, 2012 06:14 AM|LINK
Hi
Pass the FormCollection in your action, like this:
public class MyController { public ActionResult MyAction (FormCollection form) { string value = form["DropDownListName"]; } }Hope this helpful
Regards
Young Yang
Feedback to us
Develop and promote your apps in Windows Store