ASP.NET form validation mvc!

1

I have a form that validates the fields when trying to send information, but I have a "novapagina" option where I would not like to validate the fields, would that be possible?

In views

<div class="container droppedHover">
    <br/>

    <div class="relative">
        <img src="~/Content/images/Checkmark.fw.png" alt="logo" class="img-circle">
    </div>

    <br/>


@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
    @Html.ValidationSummary(true)


        <div class="row">
            <div class="span6">
                @Html.TextBoxFor(x => x.login, new { placeholder = "correo electrónico", @class = "form-control input-lg" })
                @Html.ValidationMessageFor(x => x.login)
                @Html.TextBoxFor(x => x.senha, new { placeholder = "password", @class = "form-control input-lg", type = "password" })
                @Html.ValidationMessageFor(x => x.senha)
            </div>
        </div>

        <br />

        <div class="row">
            <div class="span6">
                <button class="btn btn-lg btn-block btn-primary " type="submit" name="opcao" value="pesquisar" >Login...</button>
                <button class="btn btn-lg btn-block btn-warning " type="submit" name="opcao" value="novapagina" >¿Olvidó la contraseña?</button>
            </div>
        </div>




    if (TempData["msg"] != null)
    {
        <div class="alert alert-info alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>@TempData["msg"]</strong>
        </div>

    }
    else if (TempData["erro"] != null)
    {
        <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>@TempData["erro"]</strong>
        </div>
    }




}




</div>

No Controller

        [HttpPost]
        public ActionResult Index()
        {
            string opcao = Request["opcao"];

            if (opcao == "novapagina")
            {
              return RedirectToAction("index", "RecuperaSenha");

            }
            else
            {
                //aqui vai pesquisar o login é senha
                return View();
            }

        }
    
asked by anonymous 28.12.2015 / 05:00

1 answer

1

Any control of the page that is of type "submit" will go through the validations. What you can do is to change your redirect button to a href , and just leave the other as a "submit", redirecting by Razor. Try this:

<div>
 <button class="btn btn-lg btn-block btn-primary " type="submit"
     name="opcao" value="pesquisar" >Login
 </button>

  <a href="@Url.Action("Index", "RecuperaSenha")" class="btn btn-lg btn-block btn-warning">
    <span>Nova Página</span>
  </a>
</div>
    
28.12.2015 / 17:20