Asp.net不能向控制器发布价值

时间:2017-12-15 22:16:23

标签: asp.net post

我想将电子邮件和密码发布到另一个控制器的操作(创建) 但是没有公布价值。当我看到User1Controller时,它的写入值就像屏幕截图中的Null一样。请帮助我坚持这个时间,不能理解

ScreenShot

我的User1.cs

     public partial class Users1
{
    public string userEmail { get; set; }
    public string userPassword { get; set; }
}

我的User1Controller

        [HttpPost]
        [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "userEmail,userPassword")] Users1 baska)
    {
        if (ModelState.IsValid)
        {
            db.Users1.Add(baska);
            db.SaveChanges();
            return RedirectToAction("Index","Home");
        }
        return RedirectToAction("Login", "Home");
    }

我的Login.cshtml文件

@using (Html.BeginForm("Create","Users1",FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="custom-login-panel">
    <div class="container">
        <div class="row">
            <div class="col-md-offset-3 col-md-6">
                <img class="profile-img" src="~/images/userlogo.svg"
                     alt="">
                <div class="form-login">
                    <h4 style="color:white;">Giriş ve Kayıt Ekranı</h4>
                    <div class="form-group">
                        @Html.EditorFor(m => m.user1.userEmail, new { htmlAttributes = new { @class = "form-control" ,placeholder="Email" } })
                        @*@Html.ValidationMessageFor(model => model.user1.userEmail, "", new { @class = "text-danger" })*@
                    </div>
                    <div class="form-group">
                        @Html.EditorFor(m => m.user1.userPassword, new { htmlAttributes = new { @class = "form-control", placeholder = "Passwordd" } })
                        @*@Html.ValidationMessageFor(model => model.user1.userPassword, "", new { @class = "text-danger" })*@
                    </div>
                    <div class="wrapper">
                        <div class="form-group">
                            <span class="group-btn">
                                <input style="width:40%;" type="submit" value="Giriş" class="submit btn btn-primary">
                                <input style="width:40%;" type="submit" value="Kayıt Ol" class="submit btn btn-primary">
                            </span>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
}

1 个答案:

答案 0 :(得分:0)

在您的Login.cshtml上:

you should declare your model.

在您的httpget操作上:     您应该声明一个Users1类的新实例,并将其作为参数传递给return()方法。

在您的httppost操作上:     您应该将模型作为参数接收。

我想通过这些改变,它会起作用。