我在asp.net mvc 5中使用了bootstrap模式。但是我遇到了模态问题而我无法提交数据。我已经调用_regiserPartial View表格_Layout(母版页)。
我的控制员:
[HttpPost]
public ActionResult Register(UserViewModel model)
{
var userViewModel = Mapper.Map<UserViewModel, User>(model);
if (ModelState.IsValid)
{
userViewModel.Status = true;
_userService.InsertUser(userViewModel);
model = new UserViewModel();
}
return View(model);
}
我的_registerPrtial查看:
@model HoiCode.Web.Models.Users.UserViewModel
<form class="form-horizontal">
<div id="registerModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Resgister</h4>
</div>
@using (Html.BeginForm("Register", "User", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="modal-body">
<div class="form-group">
<label class="col-sm-4 control-label">@Html.LabelFor(m => m.Email)</label>
<div class="col-sm-8">
@Html.TextBoxFor(m => m.Email, new { @type = "email", @class = "form-control" })
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">@Html.LabelFor(m => m.Password)</label>
<div class="col-sm-8">
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
}
</div>
</div>
</div>
<script>
$(document).ready(function () {
$('.launchRegisterModal').click(function () {
$('#registerModal').modal({
keyboard: false
});
});
});
</script>
我的_layout:我将从这里调用_registerPartial
<a href="#" class="launchLoginModal">Register</a>