Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 用于传递新值MVC的Html.edit_Asp.net Mvc_Razor - Fatal编程技术网

Asp.net mvc 用于传递新值MVC的Html.edit

Asp.net mvc 用于传递新值MVC的Html.edit,asp.net-mvc,razor,Asp.net Mvc,Razor,我一直在四处寻找,试图弄明白这一点,但没有运气 我要做的是传递登录者的UserId,我已经从模型的UserId中获得了这个用户id。我有下面的代码,需要传入UserID,而不是上次的更新 <div class="form-group"> @Html.LabelFor(model => model.last_update_by_IN, new { @class = "control-label col-md-2" }) <div cl

我一直在四处寻找,试图弄明白这一点,但没有运气

我要做的是传递登录者的UserId,我已经从模型的UserId中获得了这个用户id。我有下面的代码,需要传入UserID,而不是上次的更新

    <div class="form-group">
        @Html.LabelFor(model => model.last_update_by_IN, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.last_update_by_IN)
            @Html.ValidationMessageFor(model => model.last_update_by_IN)
        </div>
    </div>

将0传递到数据库是什么意思?如果.value为10,它将返回10。显示您的POST方法。编辑并添加了我的控制器代码最佳猜测是您没有在[BindInclude=…]中包含属性名称。默认情况下,所有属性都包括在内,因此如果您不想这样做,那么只需删除该属性。好的,那么删除上次更新的用户并添加用户ID?如果您不包括控件,则不会发回一个值,它将是默认值,即假设其int,则该值将为0。因为它看起来是一个您不想编辑的值,所以隐藏的输入似乎更合适,即@Html.HiddenForm=>m.UserID
    <div class="form-group">
        @Html.LabelFor(model => model.last_update_by_IN, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.UserID)
            @Html.ValidationMessageFor(model => model.last_update_by_IN)
        </div>
    </div>
    public ActionResult Edit([Bind(Include="column names here")] User_Accounts user_accounts)
    {
        if (ModelState.IsValid)
        {
            db.Entry(user_accounts).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        ViewBag.user_type_id_IN = new SelectList(db.User_Type, "userId", "userType", user_accounts.user_type_id_IN);
        ViewBag.userId = new SelectList(db.Userinfo, "userId", "pinId", user_accounts.user_id_IN);
        return View("Edit", user_accounts);
    }