2016-11-04 77 views
0

我在我的项目上有重置密码功能。我正在使用令牌向用户发送链接。点击链接后,我需要进入我的HomeController并激活ResetPassword方法。我的问题是,我不确定在哪里放置ResetPassword部分视图(这是模式),无论我放在哪里,它都会在我打开登录页面时引入。我应该在哪里放置我的部分视图

考虑用户电子邮件此链接:

http://...myurlaction=resetpassword&userid=5&[email protected]&token=1234564

当他们点击它,我需要去这个方法:

首先得获得方法:

[HttpGet] 
[Route("resetpassword")] 
[AllowAnonymous] 
public ActionResult ResetPassword(ResetPasswordRequest resetPasswordRequest) 
{ 
    //check if Token is valid show the view 
    return PartialView(); 
} 

发帖后,去POST方法:

[HttpPost] 
[Route("resetpassword")] 
public ActionResult ResetPassword(ResetPasswordView resetPasswordView) 
{ 
    return PartialView(); 
} 

,这是局部视图:

<div id="myModal" class="modal"> 
<div class="modal-content"> 
    <span class="close">x</span> 
    @using (Html.BeginForm("resetpassword", "Home", FormMethod.Post)) 
    { 
     <h5>Reset Your Loan Center Password</h5> 
     <table> 
      <tr><td>Email Address</td><td><input type="email" name="Email" placeholder="[email protected]"></td></tr> 
      <tr><td>Password</td><td><input type="Password" name="Password" placeholder="Create Password"></td></tr> 
      <tr><td>Confirm Password</td><td><input type="Password" name="ConfirmPassword" placeholder="Re-enter Password"></td></tr> 
      <tr><td colspan="2"><input type="submit" value="Reset Password"></td></tr> 
      <tr> 
       <td class="errMessage" colspan="2"> 
        @Html.ValidationSummary(true) 
       </td> 
      </tr> 
     </table> 
    } 
</div> 

我的问题是,我不知道我必须有@Html.Partial("Login") ,因为无论我有它显示重置密码查看就算我不不需要显示它。

+0

您POST方法也需要'[使用AllowAnonymous]' - 用户尚未授权(他们不应该有相同的签名) –

+0

@Stephen Muecke,事情是去后,我张贴在视图中输入值但不会去获取。 – Alma

回答

1

根据你的描述,我猜你使用PartialView,因为你想重用Login页面的代码。基本上,您的Login页面有两个状态:一个用于登录,另一个用于重置密码。要知道哪个状态被激活时,你应该有一个标志在你Login页,是这样的:

@if (Viewbag["state"] == "Login") { 
    Html.RenderPartial("Login"); 
} else { 
    Html.RenderPartial("resetpassword"); 
} 

然后,你所要做的就是设置Viewbag的合适的值在您LoginControllerResetPasswordController,像这样的东西:

[HttpGet] 
[Route("resetpassword")] 
[AllowAnonymous] 
public ActionResult ResetPassword(ResetPasswordRequest resetPasswordRequest) 
{ 
    //check if Token is valid show the view 
    Viewbag["state"] = "ResetPassword"; 
    return YourLoginPage(); 
} 
0

如果我正确地理解了你的问题,当你从家庭控制器调用partial时,局部视图应该在应用程序的Views \ Home文件夹中。作为一个建议,也许你可以将你的操作方法移到一个账户控制器,严格来说,重置密码更多的是“账户”功能,而不是驻留在你的家庭控制器中的东西。在这种情况下,您的部分视图将被添加到视图\帐户。

+0

我的意思是我必须把@ Html.Partial(“resetpassword”) – Alma

相关问题