我在用户登录后发送了回传网址:
e.g。
/Account/SignIn?ReturnUrl=%2fToDoItems%2fCreate
但是,控制器中的值不是绑定。
[HttpPost]
[ActionName("SignIn")]
public ActionResult SignInConfirmation(UserCredentialsModel model, string returnUrl)
{
if (ModelState.IsValid)
此外,Request.QueryString
为空(禁止Length
)。
如何将查询字符串参数绑定到控制器?
如下所示,我已尝试将参数名称大写:
public ActionResult SignInConfirmation(UserCredentialsModel model, [Bind(Include = "ReturnUrl")] string ReturnUrl)
答案 0 :(得分:2)
您想从 HttpGet 方法中检索 ReturnUrl ,并在回发时将其发回。
@using (Html.BeginForm("SignInConfirmation", "YOUR_CONTROLLER",
new { ReturnUrl = ViewBag.ReturnUrl },
FormMethod.Post, new { role = "form" }))
{
....
}
public ActionResult SignInConfirmation(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
[HttpPost]
public ActionResult SignInConfirmation(UserCredentialsModel model, string returnUrl)
{
}