Good morning. I work in a MVC C # project and I have a model that represents a table in my database, the model below only represents some properties of my class so as not to create confusion and represent the data of a single Event, the data of a single Company and the data of all the employees that the company wants to register to the event, like this:
public class Ejemplo
{
// datos de la empresa
[Required]
public string Empresa { get; set; }
[Required]
public string telefonoEmpresa { get; set; }
[Required]
public string NumeroPatronalEmpresa { get; set; }
//Datos del evento
[Required]
public string CodEvento { get; set; }
[Required]
public string NombreEvento { get; set; }
// Datos del empleado
[Required]
public string ID { get; set; }
[Required]
public string Cargo { get; set; }
[Required]
public string Salario { get; set; }
}
in my controller [HttpGet] I only create the view
public ActionResult ObtenerSolicitudCapacitacion() {
return View();
}
and the view is strongly typed with the previous class
now my view contains the data of the event, of the company and I want that I can register as employees as the company wishes to the event, for it the last two fields of my model can be specified the times that the company wants in the same form, that is, in the view: A company can register as many employees as it wishes to a single event in the same application.
To present the employees that the company is registering I have created a very simple HTML table that once the company specifies the data of the emleta presses a button and through jQUery I add the data to the table
@*dato de empleado a mostrar en la tabla HTML*@
<div class="form-group">
@Html.LabelFor(model => model.Cargo, new { @class = "control-label col-md-2", id = "inputText1" })
<div class="col-md-10">
@Html.EditorFor(model => model.Cargo)
@Html.ValidationMessageFor(model => model.Cargo)
</div>
</div>
@*dato de empleado a mostrar en la tabla HTML*@
<div class="form-group">
@Html.LabelFor(model => model.Salario, new { @class = "control-label col-md-2", id = "inputText2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Salario)
@Html.ValidationMessageFor(model => model.Salario)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button type="button" class="btn btn-default" id="cargarTabla">Ingresar Empleado</button>
</div>
</div>
and my jQuery that adds to the table the information defined in the input is as follows
$("#cargarTabla").click(function(e) {
e.preventDefault();
var salario = $("#inputText1").val().toLowerCase();
var cargo = $("#inputText2").val();
$('#myTable tbody').append('<tr><td for="salario">' + salario + '</td><td for="cargo">' + cargo + '</td><td><a href="#" id="select">Modificar</a><a href="#" id="eliminar"> Eliminar</a></td></tr>');
$("#inputText1").val('');
$("#inputText2").val('');
$("#inputText3").val('');
$('#inputText1').focus();
});
Now I will have the data of a single event, a single company and several employees of the company (whose data is in the HTML table) in my form and I want to send all this data to my controller that I imagine should receive List, could you indicate me How should I send the information to my controller please?