-1

以下のようにViewBagに値を設定したい

 public ActionResult Register(Guid accountId)
 {
            ViewBag.AccountId = accountId;

            return View("Register", "Account");
  }

登録ビュー内で、次のように設定できますか

 @Html.HiddenFor(m => m.AccountId, new { id = "hdaccountid", value = ViewBag.AccountId })

モデル プロパティを ViewBag 値で更新したい。したがって、コントローラー内でモデルを更新する場合、モデル プロパティには適切な値が含まれます。

ModelView を使用したくありません。提案してください。

4

1 に答える 1

1

わかっていたら…

HiddenForビューにモデルを渡さないと使えません。

意見

@Html.Hidden("accountId",  ViewBag.AccountId )
@Html.Hidden("id",  "hdaccountid" )

コントローラ

// pass parameter to view
[HttpGet]
public ActionResult Register(Guid accountId)
{
    ViewBag.AccountId = accountId;

    return View();
    //return View("Register", "Account");
}

// post parameter from view
[HttpPost]
public ActionResult Register(Guid accountId, string id)
{
    // Get model from DB and change it
    // model.accountId = accountId;
    ...
}
于 2013-01-23T11:38:04.273 に答える