こんにちは。
Windows10でASP.NETのアプリケーションを開発しています。
Visual Studio 2017 Communityを使っています。
###前提・実現したいこと
Viewの変数を理解したいです。
###試したこと
Visual StudioでCodeFirstでテーブルを作り、ScaffoldingでEdit.cshtmlを作りました。
###発生している疑問点
1行目で「model」を定義しています。(たぶん)。
emailの表示を、
email表示(改)のようにすると、@model.emailでなく@Model.emailとmodelを大文字で書き始める必要があります。
Q1)この@Modelはどこから現れたのでしょうか?
Q2).cshtmlでは、modelとModelは同じになる?
Q3)そもそも1行目は変数定義と考えてよい?
Q4)modelとModelは違うもの?
Q5)modelとModelは違うものだとしたらなぜ同じ値が入っている?
C#
11行目 2@model ConnectionList.Models.Person 3 4email表示 5@Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" }) 6 7email表示(改) 8<input type="text" value="@Model.email" />
###該当のソースコード
C#
1@model ConnectionList.Models.Person 2 3@{ 4 ViewBag.Title = "Edit"; 5} 6 7<h2>Edit</h2> 8 9 10@using (Html.BeginForm()) 11{ 12 @Html.AntiForgeryToken() 13 14 <div class="form-horizontal"> 15 <h4>Person</h4> 16 <hr /> 17 @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 18 @Html.HiddenFor(model => model.Id) 19 20 <div class="form-group"> 21 @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" }) 22 <div class="col-md-10"> 23 @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) 24 @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) 25 </div> 26 </div> 27 28 <div class="form-group"> 29 @Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" }) 30 <div class="col-md-10"> 31 @Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "form-control" } }) 32 @Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" }) 33 </div> 34 </div> 35 36 <div class="form-group"> 37 @Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" }) 38 <div class="col-md-10"> 39 <input type="text" value="@Model.email" /> 40 </div> 41 </div> 42 43 <div class="form-group"> 44 <div class="col-md-offset-2 col-md-10"> 45 <input type="submit" value="Save" class="btn btn-default" /> 46 </div> 47 </div> 48 </div> 49}
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2017
Version 15.0.26228.9 D15RTWSVC
Microsoft .NET Framework
Version 4.6.01586
です。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/18 05:38
2017/05/18 05:54 編集
2017/05/18 05:57
2017/05/18 06:17
2017/05/18 08:26
2017/05/22 00:40
2017/05/22 00:52
2017/05/22 01:07
2017/05/22 01:36
2017/05/22 02:31
2017/05/22 02:39
2017/05/22 07:04
2017/05/22 07:10
2017/05/22 07:48
2017/05/23 08:37
2017/05/23 10:45 編集
2017/05/23 10:56
2017/05/26 04:35
2017/05/26 04:42
2017/05/26 04:54