c# - Model Values Getting Lost During PostBack -


i'm trying pass model controller. have included fields of model in form 2 parts of model getting lost once makes controller, employees , employeesinmultiplecompanies, both of type ilist. have verified fields present when passed view, don't make controller.

.cshtml

@using (html.beginform("postemail","import",formmethod.post)) {     @html.antiforgerytoken()     @html.validationsummary(true)      <fieldset>         <legend>emailviewmodel</legend>         <p>             <input type="email" name="emailaddresses" value=" " required="required" />             <span class="btn_orange"><a href="#" class="remove_field" >x</a></span>         </p>         <p>             <span class="btn_orange"><a class="add_email_button" href="#">add email</a></span>         </p>         @html.hiddenfor(m=> model.employees)         @html.hiddenfor(m=> model.companyid)         @html.hiddenfor(m=> model.companyname)         @html.hiddenfor(m=> model.payfrequency)         @html.hiddenfor(m=> model.firstpayperiodbegindate)         @html.hiddenfor(m=> model.lastpayperiodenddate)         @html.hiddenfor(m=> model.numberpayperiods)         @html.hiddenfor(m=> model.validemployees)         @html.hiddenfor(m=> model.invalidemployees)         @html.hiddenfor(m=> model.employeesinmultiplecompanies)         @html.hiddenfor(m=> model.totalemployeecount)         <p>             <input type="submit" value="send email" />         </p>     </fieldset> }  <div>     @html.actionlink("cancel", "continue", "import") </div>  <script type="text/javascript">     $(document).ready(function () {         $('body').on('click', '.remove_field', function () {             $(this).closest('p').remove();         });         $('.add_email_button').closest('p').click(function () {             var html = '<p><input type="email" required="required" name="emailaddresses" /><span class="btn_orange"><a href="#" class="remove_field">x</a></span></p>';             $(html).insertbefore($(this));         });          $(body).on('click', 'submit', function() {             $('email').attr('required', true);         });     }); </script> 

controller .cs

public actionresult sendemail(importviewmodel model)         {             var editedemployees = model.employeesinmultiplecompanies;             var importmodel = tempdata["importmodel"] importviewmodel;              //for each employee in multiple companies, set user-chosen company id , cohd related company             var importservice = new importservice();             importservice.updateemployeesinmultiplecompanies(editedemployees, importmodel.employees);             tempdata["importmodel"] = importmodel;              return this.razorview("sendemail", importmodel);         }           [httppost]         public actionresult postemail(importviewmodel model)         {             iemailer emailer = new emailer();             emailer.sendemail(model.emailaddresses, model.employees);             var employees =                 model.employees.where(e => !string.isnullorwhitespace(e.validationerrororexception)).tolist();             var emailviewmodel = new emailviewmodel(employees);             return this.razorview("continue", emailviewmodel);         } 

values inserted hidden fields serialized string so.

ilist<t> not serializable because interface , and therefore cannot stored in hidden field.

see this question more detail

how convert ilist<t> regular list?


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -