我正在做一個密碼重置專案。
用戶會收到一封電子郵件,其 URL 如下:mysite.com/ResetPass?id=10&token=233rgths567sdsfg
這在 url 中包含用戶 ID 和 JWT 令牌作為引數。
MVC 控制器顯示密碼重置頁面。
[HttpGet("ResetPass")]
public IActionResult ResetPass([FromQuery] int id, [FromQuery] string token)
{
// How to send the id and token from the Url query string to the Button???
return View("ResetPass");
}
// Reset Password Button
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> ResetPassButton()
{
// How to access the user id and token?
}
我想在這個頁面上有一個表單,允許用戶更改他們的密碼,然后將新密碼、用戶 ID 和令牌發送到 API 進行處理。
但是如何將變數從 url(用戶 ID 和令牌)獲取到按鈕?
我是否只使用 Viewbag 并將它們傳遞給頁面?或者有沒有辦法讓按鈕只訪問 URL 查詢字串?
uj5u.com熱心網友回復:
您可以創建重置密碼模型并傳遞此模型。例子:
public class ResetPasswordModel
{
public int Id { set; get; }
public string Token { set; get; }
}
然后:
public IActionResult ResetPass([FromQuery] int id, [FromQuery] string token)
{
var model = new ResetPasswordModel {
Id = id,
Token = token,
}
return View("ResetPass", model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> ResetPassButton(ResetPasswordModel model)
{
// do something with model
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/407666.html
標籤:
