我需要通过 AJAX 提交数据,但只有一个空字符串到达ActivateUser
方法。
这是标记
@model String
<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">Benutzer aktivieren</h4>
</div>
<div class="modal-body">
<div id="activateresult"></div>
<div style="display: none" id="activateUserSuccess" class="alert alert-success">Der Benutzer konnte erfolgreich aktiviert werden :)</div>
<div style="display: none" id="activateUserFailure" class="alert alert-danger">Leider konnte der Benutzer nicht aktiviert werden :(</div>
<div class="list-group">
@foreach (var item in @deactivatedUsers) {
using (Ajax.BeginForm("ActivateUser", "Settings", new AjaxOptions() {
HttpMethod = "POST",
OnSuccess = "activateSuccess(response)",
OnFailure = "activateFailure(jqXHR, textStatus, errorThrown)",
UpdateTargetId = "activateresult"
}, new {
@class = "list-group-item"
})) {
<h4>
@item.Username
@Html.Hidden("Username")
</h4>
<input class="btn btn-success" type="submit" name="@item.ID" value="Aktivieren" />
}
}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Fertig</button>
</div>
</div>
</div>
这是控制器方法
[HttpPost]
public ActionResult ActivateUser(string username) {
try {
customerModel.ActivateUser(username);
return new JsonResult() { Data = true };
} catch (Exception ex) {
return new JsonResult() { Data = false };
}
}
您可以在github上查看整个代码
我究竟做错了什么?