* Razor - TextBoxForにデフォルト値を設定する [#u70d8c0d]

** 方法1 Valueプロパティを設定する [#x8ee9d96]
*** Controller [#a9f4e87d]
 public ActionResult Index()
 {
     //here you must set VALUE what u want,
     //for example I set current date
     Viewbag.ExactlyWhatYouNeed = DateTime.Now 
 
     return View();
 }

*** View [#pcb1fa8c]
 @Html.TextBoxFor(model => model.CurrentDate, new { @Value = ViewBag.ExactlyWhatYouNeed})

** 参考 [#j176cea2]
*** 参考 [#db1daf5f]
http://stackoverflow.com/questions/16625460/how-to-set-default-value-html-textboxfor

** 方法2 TextBoxを使う [#ra6e45b9]
 @Html.TextBox("CurrentDate", ViewBag.ExactlyWhatYouNeed)
*** 参考 [#od32bf37]
http://mohit-aspnet.blogspot.jp/2012/08/mvc-set-default-value-in-htmltextboxfor.html



トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS