0

I have 2 table inside a form as such

     @using (Html.BeginForm("EditData", "Edit", FormMethod.Post, new { id = "SubmitForm", role = "form", enctype = "multipart/form-data" }))
    {

     <table>
        <tr>
         .....
        <td>
        <input type="hidden" name="FacilityId" value="@datas.data1" />
        </td>
        </tr>
    </table>

        <table id="tableid2" name ="tablename2">
        <tr>
         ....
        <td>
        <input type="hidden" name="FacilityId" value="@datas.data1" />
         ....
        </td>
        </tr>
    </table>
}

using the method post i have managed to get the datas in the controller.

string[] targetids = Request.Form["FacilityId"].Split(',');

But i have no way of differentiating the data of table 1 and 2. Is there any way to differentiate between these 2 tables? Note : since i cloned the data from table 1 to table 2 I have no way of changing the table name manually. and im unfortunately not allowed to move the begin form to only include table2

  • In order to clone the html, you must of used javascript, so you can obviously change the `name` attribute. But your 2 inputs will be sent and bound in the order they are in the DOM –  Mar 06 '18 at 09:30
  • I cloned the table as such. and i tried so long to try change the name to no avail. thats why i was thinking of differentiating the form datas instead. var getSelectedRows = $(".table-striped-r tbody input:checked").parents("tbody tr").clone(); $("#TargetFacilityTable tbody").append(getSelectedRows); – user9177098 Mar 06 '18 at 09:33
  • You do not need to change the name (I just pointed out you can). The value of the inputs will be bound n the same order they appear in the DOM, so the 1st item in the array will be the value from the 1st table, and the 2nd item in the array will be the value from the 2nd table –  Mar 06 '18 at 09:46
  • but then what if table 1 has N number of facilityID and table 2 has X number of facilityId? I tried looking at the data obtained earlier and it's a single entry for each row... unless theres something wrong in my code – user9177098 Mar 06 '18 at 09:54
  • You made no mention of that in your question! And that makes your code even more crazy. I can only assume you do not understand how to generate a view correctly for collections. If your dynamically adding collection items, then start by looking at the options in [this answer](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308) –  Mar 06 '18 at 09:57
  • i know the code is crazy. i have to continue on my friend's work and i'm afraid of changing anything in his code... trust me you havent seen the craziest of them all. But anyway thx it seems that changing the name is only the viable option and i'll try to change the names in table 2 – user9177098 Mar 06 '18 at 10:03

0 Answers0