asp.net mvc - Pass Object from view to controller using mvc4 -


view

@if (weekmaster != null)  {   using (html.beginform("updateplan", "generalplan", formmethod.post, new {  }))   {   <table class="table-bordered">    <tr>    @foreach (termmaster obj in weekmaster.tolist())     {     <td align="center">    <span>  @obj.termstartdate.tostring("dd mmm") - @obj.termenddate.tostring("dd mmm")</span>     <br />     <input type="hidden" name="objhid" value="@obj" />     <input type="hidden" name="startdate" value="@obj.termstartdate" />     <input type="hidden" name="enddate" value="@obj.termenddate" />     <input type="text" style="width:80%" name="weeksession" />   </td>  }   <td>  <input type="submit" value="update" class="btn-primary" />   </td>  </tr>  </table>  } } 

controller

   [httppost]     public actionresult updateplan(list<datetime> startdate, list<datetime> enddate, list<int> weeksession, list<termmaster> objhid)     {         return view();     } 

i trying pass class object view controller above termmaster class object pass using input method <input type="hidden" name="objhid" value="@obj" /> showing null value if pass single value startdate , enddate work fine.

what wrong in code? how pass class object list in post method?

please refer image enter image description here

you can not bind objects controller input. can serialize object json. in controller can take inputs value string , deserialize it.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -