How can I pass information as a view from a controller and then return it to the controller using asp.net mvc?

I'm sure it's easy, but I can't seem to find it.

I have two tables linked to each other in sql;

   table1 with field named idTable1, info
   table2 with field named idTable1, idTable2, moreInfo

      

when i show a view that can add a new row to table2 i have access to idTable1

 <%=Html.Encode(Model.idTable1)%>

      

but when i submit the form i lose this information, in the controller IdTable1 is empty now

how to fix this "problem"?

thanks!

0


a source to share


1 answer


Instead of using, Html.Encode

you can try using Html.Hidden

. Example:

<form>
...
<%= Html.Hidden("idTable1", Model.idTable1) %>
...
</form>

      



This will send the value for idTable1

along with the form data.

+1


a source







All Articles