Call server action on dropdown list change?

296 views
Skip to first unread message

paulw...@googlemail.com

unread,
Mar 20, 2013, 1:37:16 PM3/20/13
to knocko...@googlegroups.com


Any idea how to call a server action whenever my dropdown list selects a new value.

Here's my attempt so far....

    <select @ko.Bind.Options(m => m.Markets).Value(m => m.SelectedMarket).ValueUpdate(KnockoutValueUpdateKind.Change) onchange="@ko.ServerAction("MarketSelected", "BackupFee", new { marketSelected = "abc" })"></select>


I'm using onchange to call my server action, but can't seem to pass the dropdown list selected value, hence 'abc'

Perhaps I should be using @ko.Html.DropDownList, but I can't find an example showing how to call a server action when the value changes.

I am new to KnockoutMvc, so any help appreciated.

Regards,

Paul


mq

unread,
Nov 28, 2014, 6:06:59 PM11/28/14
to knocko...@googlegroups.com
Did you find a solution?

KE

unread,
Jan 22, 2015, 12:25:37 PM1/22/15
to knocko...@googlegroups.com
I too have this exact same use case.  KnockoutMVC, Multiple Dropdown lists,  1st list change cascades to second list...      little to no documentation on how to properly do this with KnockoutMvc.

With traditional knockout you subscribe to the viewmodels property... but i'm not sure if that's the 'correct way' with knockoutMvc. 

SJ

unread,
Jun 11, 2015, 4:20:38 PM6/11/15
to knocko...@googlegroups.com
Do you have the model on your ActionResult? Since you have ValueUpdate Change your SelectedMarket property it should be what the selected option value is.

public ActionResult(MarketViewModel model)
{
     var selectedMarket = model.SelectedMarket;
     
     return Json(model)
}

Reply all
Reply to author
Forward
0 new messages