Home > other >  Return Null in Reset Password in ASP.NET Core
Return Null in Reset Password in ASP.NET Core

Time:10-06

I have a function for forget and reset password. forgot password works correct and send email correctly and return Email Active code too. but why for reset always returns null ?

RessetPassword function:

    [Route("ResetPassword")]
    [HttpGet]
    public IActionResult ResetPassword()
    {
        
        return View();
    }

    [Route("ResetPassword")]
    [HttpPost]
    public async Task<IActionResult> ResetPassword(ResetPasswordViewModel reset)
    {
        if (ModelState.IsValid)
            
        {
            var result = await _userService.ResetPassword(reset);

            switch (result)
            {
              ....... 
                    break;
            }
        }

        return View(reset);
    }

but always return null just active code email, password and re password goes correctly frim view:

@model AryanITC.Domain.ViewModels.Account.ResetPasswordViewModel
        <input asp-for="ConfirmPassword" type="password" ConfirmPassword" ></span>

        <button type="submit" > submit </button>
       
    </form>
</div>

as i said this link return after forgot password :

https://localhost:44385/resetpassword?EmailActiveCode=0e08ae5f498d4485a7d0ccc265ebfa1a

but from view , EmailactiveCode returns NULL???

this is my view model:

public class ResetPasswordViewModel
{ 
    public string EmailActiveCode { get; set; }


    public string Password { get; set; }


    public string ConfirmPassword { get; set; }
}

CodePudding user response:

as i said this link return after forgot password :

https://localhost:44385/resetpassword?EmailActiveCode=0e08ae5f498d4485a7d0ccc265ebfa1a

When using the above request URL to access the ResetPassword endpoint, it will go to the ResetPassword Get method first, so, in the ResetPassword Get method, you can add a parameter to receive the EmailActiveCode, and then return a view model to the ResetPasswrod page, code like this:

    [Route("ResetPassword")]
    [HttpGet]
    public IActionResult ResetPassword(string EmailActiveCode)
    {
        var reset = new ResetPasswordViewModel();
        reset.EmailActiveCode = EmailActiveCode;
        return View(reset);
    }
  • Related