At the moment of receiving the parameters in the Controller from the View, the same arrive null, in the View I have the following code:
@model Syc.Visitantes.Dominio.Entidades.Usuario
@{
ViewBag.Title = "Crear Usuario";
}
<h2>Crear Usuario</h2>
<div>
@Html.ActionLink("Volver", "Index")
</div>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<label class="control-label col-md-2">Nombre</label>
<div class="col-md-10">
@Html.EditorFor(model => Model.Nombre, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => Model.Nombre, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Correo</label>
<div class="col-md-10">
@Html.EditorFor(model => Model.Correo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => Model.Correo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Código de Acceso</label>
<div class="col-md-10">
@Html.EditorFor(model => Model.CodigoAcceso, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => Model.CodigoAcceso, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Clave de Acceso</label>
<div class="col-md-10">
@Html.EditorFor(model => Model.ClaveAcceso, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => Model.ClaveAcceso, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Rol</label>
<div class="col-md-10">
@Html.DropDownList("RolId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => Model.RolId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
@Html.ActionLink("Crear", "Crear", "Usuarios")
</div>
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
And this is the controller code:
using Syc.Visitantes.Aplicacion.Controladores;
using Syc.Visitantes.Dominio.Entidades;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
namespace Visitantes.Controllers
{
public class UsuariosController : Controller
{
public ActionResult Crear([Bind(Include = "Nombre,Correo,CodigoAcceso,ClaveAcceso,RolId")] Usuario usuario)
{
if (ModelState.IsValid)
{
UsuarioControlador controlador = new UsuarioControlador();
Usuario usuarioCreador = new Usuario();
controlador.Crear(usuario);
return RedirectToAction("Index");
}
return View(usuario);
}
}
}
But when verifying I realize that user receives the null values from the view.