Sending form with Asp net mvc5

Asked

Viewed 60 times

1

Good morning, I have a form to send where the button is outside the form, this form has 50 different fields, I did in html and I need to receive this data via post in a controller c#, but I have no idea how to receive this data, can someone give me a light? no wonder the inputs are contained in a table.

@for (int i = 1; i < 51; i++)
{
    if (i < 10)
    {
        <tr>
            <div class="input-group input-group-sm justify-content-center row col-12">
                <td class="p-0">
                    <div class="input-group-prepend">
                        <span class="input-group-text" style="font-size:19px" id="inputGroup-sizing-sm">&nbsp;&nbsp;&nbsp;&nbsp; @i </span>

                    </div>
                </td>
                <td class="p-0">
                    <input type="text" name="inputN_@i" class="form-control form-control-lg" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">


                <td class="p-0">
                    <input type="text" name="inputN2_@i" class="form-control form-control-lg" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
                </td>

            </div>
        </tr>
    }
    else
    {
        <tr>
            <div class="input-group input-group-sm justify-content-center ">
                <td class="p-0">
                    <div class="input-group-prepend">
                        <span class="input-group-text" style="font-size:19px" id="inputGroup-sizing-sm">&nbsp;&nbsp; @i </span>

                    </div>
                </td>
                <td class="p-0">
                    <input type="text" name="inputN_@i" class="form-control form-control-lg" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">


                <td class="p-0">
                    <input type="text" name="inputN2_@i" class="form-control form-control-lg" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
                </td>

            </div>
        </tr>
    }
}
  • If you are using MVC, it would be interesting to use a Submit (button) to post the form.

  • Unfortunately the client wants the button to be in another part of the screen totally out of the form, to revolve this I intend to send via javascript

  • If the client asks... The nut and least bad solution in my view will be to call an ajax that will pick up your fields on the screen (Selecting your form).

1 answer

1

Just you fire the submit() form via javascript...

let enviar = function(){
  document.getElementById("formulario").submit();
};
<form id="formulario">
  <input type="text" name="teste" value="teste" /> 
  
</form>
<hr/>
<input type="button" value="Submeter" onclick="enviar()"/>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.