Search code examples
htmlformscontenteditable

How do I pass contenteditable text to the server without using JavaScript?


I have an HTML table. This table has a contenteditable td, so when the user clicks a button, the text on that editable td gets passed to my POST action on the controller.

I think is simple, but I don't know how to do it, and all the related answers that I found include JavaScript code. I think is unnecessary to this case. How can I do this with using form method in the view code?

This is my code on the view

<table class="table table-hover" style="white-space:nowrap;">
    <tr>
        <th>Campo</th>
        <th>Columna en Excel</th>
    </tr>
    <tr>
        <td> Nombre</td>
        <td contenteditable="true" title="editar"  > Nombre en excel</td>
    </tr>
</table>

Note that I'm using ASP.NET MVC Framework on the server side.


Solution

  • You will have to use a textarea, there is no way you will find that submits anything to the server that is not part of a form. If you want to use something other than standard form elements you will need to use JavaScript. This is how forms work.