Приведенный ниже код демонстрирует, как перенаправить пользователя на другое действие после того, как он отправил форму.
Если вы хотите сохранить какие-либо из представленных данных для использования в методе действия, который вы перенаправляетевам нужно сохранить его в объекте TempData
.
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
// Get the e-mail address previously submitted by the user if it
// exists, or use an empty string if it doesn't
return View(TempData["email"] ?? string.Empty);
}
[HttpPost]
public ActionResult Index(string email)
{
// Store the e-mail address submitted by the form in TempData
TempData["email"] = email;
return RedirectToAction("Index");
}
}
Ваш Index
вид будет выглядеть примерно так:
@using (Html.BeginForm("Index", "Home"))
{
@* Will populate the textbox with the previously submitted value, if any *@
<input id="email" type="email" name="email" value="@Model" />
<button type="submit">Submit</button>
}