Я пытаюсь передать значение параметра запроса из HomeController в другой контроллер с именем PasscodeVerificationController, который отображает новое представление.В этом представлении есть кнопка проверки, которая принимает пароль от пользователя и отправляет обратный вызов к действию в PasscodeVerificationController, в течение всего этого процесса мне нужно передать параметр запроса, но значение, установленное в представлении Razor, теряется при обращении к методу действия
Ниже приведен код вида
@model Test.Models.PasscodeVerificationModel
@using (Html.BeginForm("verify", "PasscodeVerification", FormMethod.Post))
{
<h2>Enter your passcode here</h2>
Test.Models.SignerModel signer = ViewBag.Signer;
@Html.TextBoxFor(model => model.Passcode)
@Html.ValidationMessageFor(model => model.Passcode)
@Html.HiddenFor(x => Model.signerModel)
<input type="submit" value="Verify" />
}
Ниже приведен код контроллера
public class PasscodeVerificationController : Controller
{
[ActionName("passcode")]
public ActionResult Index(SignerModel signer)
{
/*Here signer has the value and its being passed to view and I can
confirm in the view this value exists */
ViewBag.Signer = signer;
return View("~/Views/Passcode/Index.cshtml", new PasscodeVerificationModel { signerModel = signer});
}
[HttpPost()]
[ActionName("verify")]
public ActionResult Verify(PasscodeVerificationModel tokenVerificationModel)
{
/*Signer model value is always null :( :( */
var signerModel = tokenVerificationModel.signerModel;
if (tokenVerificationModel.Passcode == "1234")
{
if (signerModel == null || string.IsNullOrWhiteSpace(signerModel.ReturnUrl))
{
return Content("No return url");
}
return Redirect(WebUtility.UrlDecode(signerModel.ReturnUrl));
}
else
{
return Content("Verification failed");
}
}
}
public class PasscodeVerificationModel
{
[Required]
[StringLength(8, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 4)]
public string Passcode { get; set; }
public SignerModel signerModel { get; set; }
}