I have a form in cshtml:

@using (Html.BeginForm("DataCheck", "Home")) { <div class="inputGroup inputGroup1"> <label id="adminLogin" for="adminlogin">Логин</label> @Html.TextBox("adminlogin", null, new { @class = "login" }) <span class="indicator"></span> </div> <div class="inputGroup inputGroup2"> <label id="adminPassword" for="adminpassword">Пароль</label> @Html.Password("adminpassword", null, new { @class = "password" }) </div> <div class="inputGroup inputGroup3"> <input type="submit" id="log_in" value="Войти" /> <p> @ViewBag.Text </p> </div> <div class="login-close-popup js-login-close-campaign"></div> } 

Here is the "DataCheck" method in the controller:

  [HttpPost] public ActionResult DataCheck (string adminlogin, string adminpassword) { if(adminlogin == "Kate_adm" && adminpassword == "1234520") { return View("Admin_Page"); } else { ViewBag.Text = "Неверно введены данные."; return View("Index"); } } 

As a result, whatever data is entered into the form, the page simply reloads, and something like this appears in the address bar:

 http://localhost:49477/?adminlogin=Kate_adm&adminpassword=1234520 

What is wrong with this code?

  • And what you do not like? Did you expect any other behavior? By the way, your code does exactly what you asked him. - AK
  • Perhaps you want to check one of the conditions when redirecting to another page. return Redirect instead of return View - AK

0