asp.net mvc - HTTP Post not returning string array -


i using mvc 4, asp.net. having issue of passing checkbox values post method in controller. returns null value.

here's part of view (get works , fills data):

@using (html.beginform()) { <fieldset>         <table>             <tr>                 @{                     int cnt = 0;                     list<learningenterprises.viewmodel.assignedvendor> techs = viewbag.tech;                      foreach (var tech in techs)                     {                         if (cnt++ % 3 == 0)                         {                             @:</tr><tr>                         }                         @:<td>                             <input type="checkbox"                                name="selectedtechs"                                value="@tech.techid"                                @(html.raw(tech.assigned ? "checked=\"checked\"" : "")) />                                @tech.techid @:  @tech.title                         @:</td>                     }                     @:</tr>                 }         </table>         <p>               <input type="submit" value="save" id="save" />         </p>         </fieldset>  } 

here's post:

[authorize(roles = "admin")]     [httppost, validateinput(false)]     public actionresult editvendor(int? id, string[] selectedtech)     {         if (id == null)         {             return new httpstatuscoderesult(httpstatuscode.badrequest);         }         var vendor = db.vendors             .include(i => i.vendortype)             .include(i=>i.stocks)             .where(i => i.id == id)             .single();          if (tryupdatemodel(vendor, "",         new string[] { "companyname", "phonenumber", "address", "provincestate", "city", "country", "postalcode", "email", "numberofbooths", "comments", "electric", "internet", "tonicequipment", "vendortypeid" }))         {            try            {                 updatevendortech(selectedtech, vendor);                 db.entry(vendor).state = entitystate.modified;                  db.savechanges();                 return redirecttoaction("index");            }             catch (exception /* dex */)            {                 //log error (uncomment dex variable name , add line here write log.                 modelstate.addmodelerror("", "unable save changes. try again, , if problem persists, see system administrator.");             }         }         populateassignedtechdata(vendor);         populatedropdownlists(vendor.vendortypeid);         return view(vendor);     } 

string[] selectedtech displaying null value in debug. supposed equal id value of checkboxes selected in view.

the first thing can see names mismatch: have string[] selectedtech in controller name = "selectedtechs" in view, asp.net binder being unable find values, sets array null.

i note don't have post url in html.beginform() if said check value in debug suppose doing other way...


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -