Asp.net mvc 数据库第一个MVC,对象未填充

Asp.net mvc 数据库第一个MVC,对象未填充,asp.net-mvc,entity-framework,asp.net-mvc-5,Asp.net Mvc,Entity Framework,Asp.net Mvc 5,我必须使用数据库优先的方法,解决方案有3个项目。两个是类库,第三个是实际的MVC项目。一个类库具有edmx设计器。另一个具有不同的模型类。MVC项目引用了这两个库。我的问题是对象没有填充值。我想这是某种命名冲突。对象tblRDBUser未填充。数据库中也有一个具有相同对象名称的表。对象属性也与列名匹配。我没有将值从视图中获取到控制器中 项目一: RDB.DataModel, it contains the EDMX designer. 项目二:RDB.Models using System;

我必须使用数据库优先的方法,解决方案有3个项目。两个是类库,第三个是实际的MVC项目。一个类库具有edmx设计器。另一个具有不同的模型类。MVC项目引用了这两个库。我的问题是对象没有填充值。我想这是某种命名冲突。对象tblRDBUser未填充。数据库中也有一个具有相同对象名称的表。对象属性也与列名匹配。我没有将值从视图中获取到控制器中

项目一:

RDB.DataModel, it contains the EDMX designer.
项目二:RDB.Models

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RDB.DataModel;

public class Authenticate
{
    public string AuthenticateUser(tblRDBUser User)
    {
        Book_TradEntities users = new Book_TradEntities();
        return (from p in users.tblRDBUsers where p.UserName == User.UserName && p.Password == User.Password select p.UserName).FirstOrDefault();
    }

}
项目3:

视图:

控制器:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using RDB.DataModel;
using RDB.Models;

namespace CignaRDB.Controllers
{
public class RDBWebController : Controller
{
    //
    // GET: /RDBWeb/
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Authenticate(tblRDBUser User)
    {
        if (ModelState.IsValid)
        {
            Authenticate user = new Authenticate();
            user.AuthenticateUser(User);
            return View();
        }
        return View();
    }
}
}

主要问题。您创建了link
@Html.ActionLink(“Login”,“Authenticate”)
,在点击他之后,只需将用户重定向到Authenticate方法。而不是一个链接,你应该生成按钮,使您的表单提交。所以视图代码应该是这样的

@model RDB.DataModel.tblRDBUser
@{
    ViewBag.Title = "Index";
}
@using (Html.BeginForm("Authenticate"))
{
   @Html.TextBoxFor(a => a.UserName)
   @Html.TextBoxFor(a => a.Password)

   <input type="submit" value="Login" />

我真的看到纯文本密码存储吗?或者这是对你的代码的简化?@trailmax哦,这是简化的代码。你必须对你的问题做更多的解释。什么对象没有填充?你认为你的图层是如何影响这个的?啊!好!!表示无明文密码存储!-)我认为你的观点中缺少了“形式”元素。您没有提到哪个对象没有填充。是不是当你点击按钮时,你没有从视图中得到控制器的值?非常感谢。
@model RDB.DataModel.tblRDBUser
@{
    ViewBag.Title = "Index";
}
@using (Html.BeginForm("Authenticate"))
{
   @Html.TextBoxFor(a => a.UserName)
   @Html.TextBoxFor(a => a.Password)

   <input type="submit" value="Login" />
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using RDB.DataModel;
using RDB.Models;

namespace CignaRDB.Controllers
{
public class RDBWebController : Controller
{
    //
    // GET: /RDBWeb/
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Authenticate(tblRDBUser User)
    {
        if (ModelState.IsValid)
        {
            Authenticate user = new Authenticate();
            user.AuthenticateUser(User);
            return View();
        }
        return View("Index");//because view name and Action method not match
    }
}
}