0

(UserUniqueId)Get 操作中に格納されたプロパティの値を取得する必要があります。

public ActionResult Create(int uniqueId = -1)
{
    w = new Work { UserUniqueId = uniqueId };
    //todo: how to pass uniqueId while rendering view. such that must receive it back during post.
    return View(w);
}

ビューはこの値を入力/更新しませんUserUniqueId。データベースの保存操作にアクセスする必要があります。

    [HttpPost]
    public ActionResult Create(Work work)
    {
        if (ModelState.IsValid)
        {
            //Set uniqueId, Set UserId
            int userId = WebSecurity.HasUserId ? WebSecurity.CurrentUserId : -1;
            work.UserId = WebSecurity.CurrentUserId;
            //Need previously stored uniqueId here.
            work.UserUniqueId = //How do I obtain this value here.
            db.SaveChanges();

            return RedirectToAction("Index");
        }

        return View(work);
    }
4

2 に答える 2