我在一个视图上有“重置密码”和“用户个人资料信息更新”部分。
我有一个带有两个子模型的父模型:ResetPwdModel 和 UserInfoModel。
对于重置密码提交和保存配置文件信息提交,我希望结果 URL 看起来相同(与当前 URL 相同),这样用户就不会感到困惑。
为了实现这一点,我重载了动作方法,一个接受 ResetPwdModel,另一个接受 UserInfoModel。但是,我收到错误消息The current request for action 'profile' on controller type 'XXController' is ambiguous...
有没有优雅的方法来解决这个问题?我的目标是能够在 1 个视图中使用两个模型,并使帖子 URL 看起来与当前 URL 相同。
模型
public class ProfileParentModel
{
public ProfileResetPwdModel ResetPwd { get; set; }
public ProfileUserInfoModel UserInfo { get; set; }
}
public class ProfileResetPwdModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Profile_lbl_OldPassword", ResourceType = typeof(Resource))]
public string OldPassword { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Profile_lbl_NewPassword", ResourceType = typeof(Resource))]
public string NewPassword { get; set; }
[Compare("NewPassword", ErrorMessageResourceName = "Profile_Error_NotMatch", ErrorMessageResourceType = typeof(Resource))]
[Required]
[DataType(DataType.Password)]
[Display(Name = "Profile_lbl_ConfirmNewPassword", ResourceType = typeof(Resource))]
public string ConfirmNewPassword { get; set; }
}
public class ProfileUserInfoModel
{
[Display(Name = "Profile_lbl_FirstName", ResourceType = typeof(Resource))]
public string FirstName { get; set; }
[Display(Name = "Profile_lbl_LastName", ResourceType = typeof(Resource))]
public string LastName { get; set; }
[Display(Name = "Profile_lbl_WorkTitle", ResourceType = typeof(Resource))]
public string WorkTitle { get; set; }
[Display(Name = "Profile_lbl_CompanyName", ResourceType = typeof(Resource))]
public string CompanyName { get; set; }
[Display(Name = "Profile_lbl_CompanyAddress", ResourceType = typeof(Resource))]
public string CompanyAddress { get; set; }
}
看法
@{
var passwordHtml = Html.HtmlHelperFor(Model.ResetPwd);
var profileHtml = Html.HtmlHelperFor(Model.UserInfo);
}
@using (passwordHtml.BeginForm())
{
//HTML goes here...
}
@using (profileHtml.BeginForm())
{
//HTML goes here...
}
控制器
[ActionName("Profile")]
[HttpPost]
[Authorize]
public ActionResult ResetPassword(ProfileResetPwdModel model)
{
return View("Profile", parentModel);
}
[ActionName("Profile")]
[HttpPost]
[Authorize]
public ActionResult SaveUserInfo(ProfileUserInfoModel model)
{
return View("Profile", parentModel);
}