我在一个包含用户详细信息的视图中有一个 Html.BeginForm:名字、姓氏、电子邮件等。然后我有 2 个按钮。批准和拒绝
单击批准后,我转到一个视图。
当拒绝时,我去另一个。
处理哪个被点击的最佳方法是什么?
在我看来:
<% using (Html.BeginForm("PublishGroupsForRecommendedUser", "Recommend", FormMethod.Post, new { id = ViewBag.UserId }))
{ %>
<div class="section _100">
<%: Html.LabelFor(model => model.Email)%>
<div>
<%: Html.EditorFor(model => model.Email)%>
<%: Html.ValidationMessageFor(model => model.Email)%>
</div>
</div>
//etc
<input type="hidden" name="action">
<div class="actions">
<div class="actions-right">
<input type="submit" value="Approve" class="submit_button" />
</div>
<div class="actions-left">
<input type="submit" value="Reject" class="submit_button" />
</div>
</div>
<% } %>
在我的控制器中:
[HttpPost]
public ActionResult PublishGroupsForRecommendedUser(int userId)
{
var recommendedUser = ZincService.UserService.GetRecommendedUserForId(userId);
var visibleGroups = ZincContext.CurrentUserGroups.Get();
var groupEntities = ZincService.GroupService.GetVisibleGroupsForUser(CurrentUser.UserId).ToList();
var viewModel = GetGroupPublishingViewModelForSelectedGroups(
recommendedUser.RecommendedUserId, Zinc.Enums.PublishingMode.ParticipatingGroupUsersOnly,
recommendedUser.Email, groupEntities);
return View(viewModel);
}
[HttpGet]
public ActionResult RejectUser(RecommendUserViewModel model)
{
Entities.RecommendedUser user = new RecommendedUser();
user.ReasonForRejection = model.ReasonForRejection;
ZincService.UserService.UpdateRecommendedUser(user);
return View(user);
}
所以我不能再使用这条线(Html.BeginForm("PublishGroupsForRecommendedUser", "Recommend", FormMethod.Post, new { id = ViewBag.UserId }))
了,因为根据点击了哪个按钮,我需要转到PublishGroupsForRecommendedUser
orRejectUser
操作,这反过来又会调用相应的视图。
有人可以推荐我最好的方法吗?