jquery - Ajax.BeginForm cannot submit dropdown list selected value -


form:

<div id="_searchtab">     @using (ajax.beginform("searchresult", "maintenance", null,          new ajaxoptions {             insertionmode = insertionmode.replace,             updatetargetid = "gridarea",             httpmethod = "get",             loadingelementid = "loading"         }, new { id = "searchbycriteria"})) { <table>     <tr>     <td>      @html.labelfor(model => model.unit_cd)                 @html.dropdownlistfor(model => model.unit_cd, new selectlist(viewbag.unitlist, "value", "text"), "-- select unit --")     </td> </tr>     <tr>     <td>         @html.labelfor(model => model.program_cd)             @html.textboxfor(model => model.program_cd)         </td> </tr>         </table>             <div id=" buttonholder">     <input id="search" type="submit" value="search"/> </div> }  </div> <div id="gridarea">    display data here </div> 

searchresult action:

[httpget]         public partialviewresult searchresult(string unitcode, string programcode) // showed both null in debug mode         {             // typical linq stuff, if parameters null, show data in partial view, if @ leastone of parameters not null, use search criteria         } 

the problem when submit form, searchresult action's both parameters show null. have tried multiple approaches including these below:

<input id="search" type="submit" value="search"  onclick="javascript:$('searchbycriteria').submit()" /> 

and this: (with javascript runtime error)

<input id="search" type="submit" value="search"  onclick ="@(url.action("searchresult", "maintenance", new { unitcode = model.unit_cd, programcode = model.program_cd})) "/> 

and adding onsubmit=return searchform() form parameters, , use javascript submit:

function searchform() {      $("#gridarea").html("");             // load searchresult partialview in gridarea div             $("#gridarea").load(                 '@(url.action("searchresult", "maintenance", new { unitcode = model.unit_cd, programcode = model.program_cd}))'                 )             return false; } 

and jquery functions either search button's click event,

$("#search").click(             function () {                 // clear grid area                 $("#gridarea").html("");                 // load searchresult partialview in gridarea div                 $("#gridarea").load(                     '@(url.action("searchresult", "maintenance", new { unitcode = model.unit_cd, programcode = model.program_cd}))'                 )         }); 

or form's submit event

$("#searchbycriteria").submit(function (event) {             $("#gridarea").html("");             $("#gridarea").load(                 '@(url.action("searchresult", "maintenance", new { unitcode = model.unit_cd, programcode = model.program_cd}))'                 )         });  

none of above can pass parameters controller. can me please?

model.

public ilist<selectedlistitem> unit_cd{get;set;} 

controller:

public actionresult index() {      model objmodel=new model();      objmodel.unit_cd=dbcontext.tablename.select(a=>new selectedlistitem{           value=a.value,           text=a.name      });    return view(objmodel); } 

mvc

@html.labelfor(model => model.unit_cd)             @html.dropdownlistfor(model => model.unit_cd, (ienumerable<selectlistitem>)model.unit_cd,"text","value", "-- select unit --") 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -