我正在尝试在MVC上为ApplicationUsers创建一个更新表单。
这是我的控制者:
// Usuarios/Modificar
[HttpPost, ActionName("Modificar")]
public ActionResult Modificar(ApplicationUser modifiedUser)
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
var applicationUser = userManager.FindById(modifiedUser.Id);
if (applicationUser != null)
{
applicationUser.Apellido = modifiedUser.Apellido;
applicationUser.Nombre = modifiedUser.Nombre;
applicationUser.Dni = modifiedUser.Dni;
applicationUser.Interno = modifiedUser.Interno;
applicationUser.Email = modifiedUser.Email;
applicationUser.UserName = modifiedUser.UserName;
userManager.Update(applicationUser);
}
}
return null;
}
这是我的观点:
@model Core.Models.ApplicationUser
@using (Ajax.BeginForm("Modificar", "Usuarios", new AjaxOptions(){ HttpMethod = "POST", }))
{
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="col-md-12">
<div class="box box-default">
<!-- #region Header del Box -->
<div class="box-header with-border">
<h3 class="box-title">Usuario: @Model.UserName</h3>
</div>
<!-- #endregion -->
<!-- #region Cuerpo del box. -->
<div class="box-body">
<!-- #region Fila 1. -->
<div class="row">
<!-- Columna 1. -->
<div class="col-md-2">
<div class="form-group">
<i class="fa fa-fw fa-user"></i> <label>Apellido: </label>
@Html.EditorFor(model => model.Apellido, new {htmlAttributes = new {@class = "form-control"}})
@Html.ValidationMessageFor(model => model.Apellido, "", new {@class = "text-danger"})
</div>
</div>
<!-- /.col -->
<!-- Columna 2. -->
<div class="col-md-2">
<div class="form-group">
<i class="fa fa-fw fa-user"></i> <label>Nombre: </label>
@Html.EditorFor(model => model.Nombre, new {htmlAttributes = new {@class = "form-control"}})
@Html.ValidationMessageFor(model => model.Nombre, "", new {@class = "text-danger"})
</div>
</div>
<!-- /.col -->
<!-- Columna 3. -->
<div class="col-md-2">
<div class="form-group">
<i class="fa fa-fw fa-user"></i> <label>Documento: </label>
@Html.EditorFor(model => model.Dni, new {htmlAttributes = new {@class = "form-control"}})
@Html.ValidationMessageFor(model => model.Dni, "", new {@class = "text-danger"})
</div>
</div>
<!-- /.col -->
<!-- Columna 4. -->
<div class="col-md-2">
<div class="form-group">
<i class="fa fa-fw fa-user"></i> <label>Mail: </label>
@Html.EditorFor(model => model.Email, new {htmlAttributes = new {@class = "form-control"}})
@Html.ValidationMessageFor(model => model.Email, "", new {@class = "text-danger"})
</div>
</div>
<!-- /.col -->
<!-- Columna 5. -->
<div class="col-md-2">
<div class="form-group">
<i class="fa fa-fw fa-user"></i> <label>Usuario: </label>
@Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
</div>
</div>
<!-- /.col -->
</div>
<!-- #endregion /.row -->
</div>
<!-- #endregion /.box-body -->
<div class="box-footer">
<div class="row">
<div class="col-md-1 pull-right">
<input type="submit" name="btnAppUser" id="btnAppUser" class="btn btn-default pull-right" value="Guardar" />
</div>
</div>
</div>
</div>
</div>
}
但是,提交后,当帖子到达控制器时,applicationUser为空。 Ajax表单不是发送信息,也不是绑定到ApplicationUser模型。谁能帮我理解这个问题呢?
谢谢!