需要使用Entity Framework的登录页面,MVC中的SQL Server

问题描述 投票:0回答:2

我需要在MVC中使用Entity Framework,SQL Server设计登录页面。我尝试了几种方法,但是它们都无法正常工作,即使结果是正确的,程序也无法将我定向到主页。现在需要帮助。

这是我的:

控制器

MainEntities1 db = new MainEntities1();
public ActionResult Index(Admin a)
    {
        if (ModelState.IsValid)
        {
            Admin admin = db.Admin.Find(1);
            db.Admin.Add(a);
            if (a.Password.Equals(admin.Password))
                    return RedirectToAction("Main");
            return RedirectToAction("Index");
        }
        return View();
    }

查看

<div class="form-horizontal">
    <h4>Admin</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Login" class="btn btn-default" />
        </div>
    </div>
</div>

在表“ Admin”中,我具有主键和密码ID。

sql-server asp.net-mvc entity-framework asp.net-mvc-5 entity-framework-6
2个回答
0
投票

行:db.Admin.Add(a);正在将实体添加到您的上下文中。这有什么意义?


0
投票

问题需要更清楚。您需要完成以下步骤:Login Functionality - MVC我希望这可以解决此错误。

© www.soinside.com 2019 - 2024. All rights reserved.