在控制器中做出反应,如果在视图中单击了操作链接
在我看来“EditUser”,我有一个操作链接,我并不总是点击它:
<%= Html.ActionLink("Resend forgotten password", "EditUser", this.Model.UserName, null)%><br />
在我的控制器“AdministrationController”中,我有一个 EditUser ActionResult,我想调用发送忘记密码的方法。但我不知道如果我点击或不点击操作链接该如何反应。我不想每次调用操作“EditUser”时都发送密码。
我在 AdministratorController 中的操作:
[HttpPost]
[ValidateInput(false)]
public ActionResult EditUser(EditUserModel model)
{
try
{
Admin admin = new Admin();
admin.SendForgottenPasswordToUser(model.UserName);
if (!model.Validate())
{
ModelState.AddModelError("", "Please fill missed fields");
}
if (!model.Save())
{
ModelState.AddModelError("", "Error while saving data");
}
else
{
ModelState.AddModelError("", "Successufully edited.");
}
return View(model);
}
In my view "EditUser" I have an action link which i click not always:
<%= Html.ActionLink("Resend forgotten password", "EditUser", this.Model.UserName, null)%><br />
In my controller "AdministrationController" i have an EditUser ActionResult there i would like to call Method which send forgotten password. But I dont know how to react if i clicked an action link or not. I dont want to send Password each time when I call Action "EditUser".
My Action in AdministratorController:
[HttpPost]
[ValidateInput(false)]
public ActionResult EditUser(EditUserModel model)
{
try
{
Admin admin = new Admin();
admin.SendForgottenPasswordToUser(model.UserName);
if (!model.Validate())
{
ModelState.AddModelError("", "Please fill missed fields");
}
if (!model.Save())
{
ModelState.AddModelError("", "Error while saving data");
}
else
{
ModelState.AddModelError("", "Successufully edited.");
}
return View(model);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个额外的操作方法并更改操作链接:
<%= Html.ActionLink("重新发送忘记密码", "ResendPassword", this.Model.UserName, null)%>
重新发送的操作方法密码看起来像这样:
You could create an extra action method and change the action link:
<%= Html.ActionLink("Resend forgotten password", "ResendPassword", this.Model.UserName, null)%>
The action method for resending the password then looks something like this: