Trabajo con ASP.NET MVC 5, tengo una vista parcial la cual cuando presiono el botón Guardar debería de persistir los datos en la db y dirigirse al Index pero no esta registrando los datos. Muestro código.
CONTROLLER
public ActionResult CreatePV()
{
var documento = SdProveedor.Lista();
ViewBag.ListaDocumento = new SelectList(documento, "Id", "Descripcion");
var model = new ProveedorDto();
return PartialView(model);
}
// POST: Proveedor/Create
[HttpPost]
public ActionResult Create(ProveedorDto entity)
{
try
{
if (ModelState.IsValid)
{
//var documento = SdProveedor.Lista();
//ViewBag.ListaDocumento = new SelectList(documento, "Id", "Descripcion");
SdProveedor.Create(entity);
return RedirectToAction("Index");
}
else
return View(entity);
}
catch
{
return View(entity);
}
}
VIEW INDEX
<div id="myModal" class="modal fade in">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header" style="background-color: #337ab7;border-color:#2e6da4;color:#fff;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h5 class="modal-title">Proveedor</h5>
</div>
<div class="modal-body">
<div id="resultado"></div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Guardar</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
PARTIAL VIEW
@model Demo.ServiciosDominio.Dtos.ProveedorDto
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@*<h4>Proveedor</h4>
<hr />*@
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<div class="col-md-5 text-right">
@Html.LabelFor(model => model.RazonSocial, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7 text-right">
@Html.EditorFor(model => model.RazonSocial, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.RazonSocial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-5 text-right">
@Html.LabelFor(model => model.DocumentoIdentidad, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7 text-right">
@Html.EnumDropDownListFor(x => x.DocumentoIdentidad, "<<SELECCIONE>>", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DocumentoIdentidad, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-5 text-right">
@Html.LabelFor(model => model.NumeroDocumento, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7 text-right">
@Html.EditorFor(model => model.NumeroDocumento, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NumeroDocumento, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-5 text-right">
@Html.LabelFor(model => model.Direccion, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7 text-right">
@Html.EditorFor(model => model.Direccion, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Direccion, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-5 text-right">
@Html.LabelFor(model => model.Telefono, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7 text-right">
@Html.EditorFor(model => model.Telefono, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Telefono, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-5 text-right">
@Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7 text-right">
@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
</div>
</div>
@*<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Guardar" class="btn btn-default" />
<input type="button" value="Cerrar" class="btn btn-default" />
</div>
</div>*@
</div>
}