c# - How to get selected drop down values from Controller MVC -


the following view :

 <div class="editor-label">         select currency :         </div>         <div class="editor-field">             @html.dropdownlist("currencyid", new selectlist(viewbag.currencyid, "value", "text"))  </div><div class="editor-label">          select gametype :         </div>         <div class="editor-field">            @html.dropdownlist("gametypeid", new selectlist(viewbag.gametypeid, "value", "text"), new { style = "width:100px" })             @html.validationmessagefor(model => model.gametypeid)         </div>          <div class="editor-label">           select category :         </div>         <div class="editor-field">           @html.dropdownlist("categorybygametype", enumerable.empty<selectlistitem>(), "select category")           @html.validationmessagefor(model => model.categoryid)         </div> 

the following controller:-

 public actionresult create()         {             list<currency> objcurrency = new list<currency>();             objcurrency = db.currencies.tolist();             list<selectlistitem> listitems = new list<selectlistitem>();             listitems.add(new selectlistitem()             {                 value = "0",                 text = "select currency"             });             foreach (currency item_currency in objcurrency)             {                 listitems.add(new selectlistitem()                 {                     value = item_currency.currencyid.tostring(),                     text = item_currency.currencyname                 });             }             viewbag.currencyid = new selectlist(listitems, "value", "text");              list<gametype> objgametype = objgamebygametype.getdistinctgametypeid();             list<selectlistitem> listitems_1 = new list<selectlistitem>();             listitems_1.add(new selectlistitem()             {                 value = "0",                 text = "select game type"             });             foreach (gametype item_gametype in objgametype)             {                 listitems_1.add(new selectlistitem()                 {                     value = item_gametype.gametypeid.tostring(),                     text = item_gametype.gametypename                 });             }             viewbag.gametypeid = new selectlist(listitems_1, "value", "text");               return view();         } 

the following jquery using casceding dropdown

$(function () {             $("#gametypeid").change(function () {                 var theatres = "";                 var gametype = "";                 var mytestvar = "";                 var gametypeid = $(this).val();              mytestvar += "<option value= -1 >select category</option>";             $.getjson("@url.action("getcategorybygametype", "gamecombination")?gametypeid=" + gametypeid, function (data) {                 $.each(data, function (index, gametype) {                   //  alert("<option value='" + gametype.value + "'>" + gametype.text + "</option>");                     mytestvar += "<option value='" + gametype.value + "'>" + gametype.text + "</option>";                 });                 //alert(mytestvar);                 $("#categorybygametype").html(mytestvar);                 $("#gamebycategory").html("<option value=0>select game</option>");                 $("#limitvariantbygamebygametype").html("<option value=0>select limit variant</option>");                 $("#stakecategory").html("<option value=0>select stake category</option>");                 $("#stakebuyinbystakecategory").html("<option value=0>select stake buy in stake category</option>");       });      });     }); 

while submit data not able dropdown value if error come on creation

echo of andras said, can't use razor syntax in .js file if that's happening.

also should familiar debugging tools, browser using? have nice set of developer tools (some have them built in) can inspect page , request sent out when submit form.

you interactively use jquery in console of browser around also.

you don't show post create method, perhaps related code?


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -