Problem with logging in .net using mvc? (it does not validate me or recognize my credentials)

0

I have created the view and the login controller but it does not validate or redirect me to the tables, in this case to the Courses once logged in, it is more, nor does it validate me if it has data or not, I show the code of the controller

public class InicioController : Controller
{
    // GET: Inicio
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]

    public ActionResult Index(Inicio model)
    {
        ColegioConnection modeloBD = new ColegioConnection();
        var usuario = modeloBD.Inicios.FirstOrDefault(x => x.Usuario == model.Usuario && x.Contraseña == model.Contraseña);

        if (usuario== null)
        {
            ViewBag.Mensaje = "Usuario y/o contraseña incorrectos";
            return View();
        }

        // se asigna el nombre del usuario que inicia sesion
        Session["Contraseña"] = usuario.Contraseña;

        return RedirectToAction("Index");
    }
}


<--ahora el de la vista del controlador: -->

@model Modelo.BaseDatos.Inicio

@{
    ViewBag.Title = "Inicio";
}

@using (Html.BeginForm("Index", "Inicio", FormMethod.Post, new { @class = "form-signin" }))
{
    <fieldset>
        <legend>Inicie Sesion</legend>

        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
        @if (@ViewBag.Message != null)
        {
            <div style="border: 1px solid red">
                @ViewBag.Message
            </div>
        }
        <table>
            <tr>
                <td>@Html.LabelFor(a => a.Usuario)</td>
                <td>@Html.TextBoxFor(a => a.Usuario)</td>
                <td>@Html.ValidationMessageFor(a => a.Usuario)</td>
            </tr>
            <tr>

                <td>
                    @Html.LabelFor(a => a.Contraseña)
                </td>

                <td>
                    @Html.PasswordFor(a => a.Contraseña)
                </td>
                <td>
                    @Html.ValidationMessageFor(a => a.Contraseña)
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="submit" value="Inicio" />
                </td>
                <td></td>
            </tr>
        </table>
    </fieldset>
}

PD2: I made the website with layers, so I am bringing the Database from a class library called Modelo.BaseDatos ('Using Modelo.BaseDatos')

What I want is for me to validate the credentials that I created in the table so that it validates me in the beginning, and if it is the opposite that does not allow me to enter, thank you very much.

    
asked by Joe Pulgarin 12.12.2017 в 17:16
source

0 answers