【问题标题】:httppost data used for database queries用于数据库查询的 httppost 数据
【发布时间】:2020-06-12 06:30:57
【问题描述】:

我有两个来自 asp MVC 实体框架视图的字符串数据字段。通过模型绑定,我现在将这些数据返回到 httppost 操作函数中。我现在想使用这些数据传递给 mysql 数据库中的查询。

查询将只是一个只读查询来获取一些记录。请提供有关如何实现此目的的任何指示?该应用程序是 MVC ASP Core EntityFramework 类型的项目。

    [HttpPost]
    public IActionResult Login(Login loginData)
    {

        if (ModelState.IsValid)
        {
            // check the parameters passed against what's in the db and if they match, do things. Else, report login/password error


        } else
        {
            // show error
        }
        return View();

    }

我是 ASP MVC/实体框架的新手。希望有任何示例链接。

【问题讨论】:

    标签: asp.net-mvc entity-framework asp.net-core mysql-connector


    【解决方案1】:

    这里是EF Core的链接,这里是EF Core with MVC的链接。

    EF Core 示例(通过 id 查找用户):

    var User=_context.Users.FirstOrDefaultAsync(u => u.id == loginData.id);
    

    【讨论】:

      猜你喜欢
      • 2015-09-18
      • 2012-07-23
      • 1970-01-01
      • 2017-09-29
      • 1970-01-01
      • 2014-11-29
      • 2013-03-03
      • 2013-08-06
      • 1970-01-01
      相关资源
      最近更新 更多