質問編集履歴

4

不要なマークダウン記法の削除

2020/06/02 13:58

投稿

Eltk
Eltk

スコア51

test CHANGED
File without changes
test CHANGED
@@ -40,168 +40,164 @@
40
40
 
41
41
 
42
42
 
43
+ 上記の実装を考えるにあたって、特に、下記の二点についてとっかかりがなく困っております。
44
+
45
+
46
+
47
+ ①Modelで定義した1つのPropertyに対して、どのようにしてViewで2つのテキストボックスに分けるのか。
48
+
49
+ ②下記「該当のソースコード」の「TestsController.vb」において、Viewでのテキストボックスの値を結合する記述を書くのはどの箇所で、どのように書けば良いのか。
50
+
51
+
52
+
53
+
54
+
55
+ ①についてですが、
56
+
57
+ 「@TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})」
58
+
59
+ のようなTextBoxForメソッドを2つ用意することを考えておりますが、
60
+
61
+ 「Funcrion(model) model.Time」の箇所はもちろん分割できないと思われますので、この箇所の書き方は検討が全くついておりません。
62
+
63
+
64
+
65
+ ②についてですが、
66
+
67
+ 各々のテキストボックスに対して、Javascriptでテキストボックスの中身を取得、結合したら良いのかなとは考えています。
68
+
69
+ ただ、その結合結果を、このCreateアクションにどうやって組み込ませれば良いのかがわかりません。)
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+ ### 該当のソースコード
78
+
79
+ ※以下はTestsController.vbのファイルです。
80
+
81
+ ※今回の質問に必要だと思われる箇所以外は一部省略し、データ挿入時のCreateアクションのみを書いております。
82
+
83
+
84
+
85
+ ```VisualBasic
86
+
87
+
88
+
89
+ <HttpPost()>
90
+
91
+ <ValidateAntiForgeryToken()>
92
+
93
+ Function Create(<Bind(Include:="Id,Time")> ByVal test As Test) As ActionResult
94
+
95
+ If ModelState.IsValid Then
96
+
97
+ db.Tests.Add(test)
98
+
99
+ db.SaveChanges()
100
+
101
+ Return RedirectToAction("Index")
102
+
103
+ End If
104
+
105
+ Return View(test)
106
+
107
+ End Function
108
+
43
109
  ```
44
110
 
111
+
112
+
113
+
114
+
115
+
116
+
117
+ ※以下はTest.vbのファイルです。
118
+
119
+ ```VisualBasic
120
+
121
+
122
+
123
+
124
+
45
- 上記の実装を考えるにあたって、特に、下記の二点についてとっかかりがなく困っております。
125
+ Imports System.ComponentModel.DataAnnotations
126
+
46
-
127
+ Imports System.ComponentModel
128
+
129
+
130
+
47
-
131
+ Public Class Test
132
+
133
+
134
+
48
-
135
+ <Key()>
136
+
137
+ <DisplayName("ID")>
138
+
139
+ Public Property Id As String
140
+
141
+
142
+
143
+ <DisplayName("時間")>
144
+
49
- ①Modelで定義した1つのPropertyに対して、どのようにしてViewで2つのテキストボックスに分けるのか。
145
+ Public Property Time As Integer
50
-
51
- ②下記「該当のソースコード」の「TestsController.vb」において、Viewでのテキストボックスの値を結合する記述を書くのはどの箇所で、どのように書けば良いのか。
146
+
52
-
53
-
54
-
55
-
56
-
147
+
148
+
57
- ①についてですが、
149
+ End Class
58
-
59
- 「@TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})」
60
-
61
- のようなTextBoxForメソッドを2つ用意することを考えておりますが、
62
-
63
- 「Funcrion(model) model.Time」の箇所はもちろん分割できないと思われますので、この箇所の書き方は検討が全くついておりません。
64
-
65
-
66
-
67
- ②についてですが、
68
-
69
- 各々のテキストボックスに対して、Javascriptでテキストボックスの中身を取得、結合したら良いのかなとは考えています。
70
-
71
- ただ、その結合結果を、このCreateアクションにどうやって組み込ませれば良いのかがわかりません。)
72
-
73
-
74
-
75
-
76
150
 
77
151
  ```
78
152
 
79
153
 
80
154
 
81
- ### 該当のソースコード
82
-
83
- ※以下はTestsController.vbのファイルです。
155
+ ※以下はCreate.vbhtmlのファイルです。(コメント欄参考用)
84
-
85
- ※今回の質問に必要だと思われる箇所以外は一部省略し、データ挿入時のCreateアクションのみを書いております。
86
-
87
-
88
156
 
89
157
  ```VisualBasic
90
158
 
91
-
159
+ @ModelType MvcApp.Test
160
+
161
+
162
+
92
-
163
+ @Using (Html.BeginForm())
164
+
165
+ @*「時間」用TextBox*@
166
+
167
+ <div class="form-group">
168
+
169
+ @Html.LabelFor(Function(model) model.Time, htmlAttributes:=New With {.class = "control-label col-md-2"})
170
+
171
+ <div class="col-md-10">
172
+
173
+ @Html.TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})
174
+
93
- <HttpPost()>
175
+ </div>
176
+
94
-
177
+ </div>
178
+
179
+
180
+
181
+ @*「分」用TextBox*@
182
+
95
- <ValidateAntiForgeryToken()>
183
+ <div class="form-group">
96
-
184
+
97
- Function Create(<Bind(Include:="Id,Time")> ByVal test As Test) As ActionResult
185
+ @Html.LabelFor(Function(model) model.Time, htmlAttributes:=New With {.class = "control-label col-md-2"})
98
-
99
- If ModelState.IsValid Then
186
+
100
-
101
- db.Tests.Add(test)
102
-
103
- db.SaveChanges()
104
-
105
- Return RedirectToAction("Index")
187
+ <div class="col-md-10">
188
+
106
-
189
+ @Html.TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})
190
+
191
+ </div>
192
+
193
+ </div>
194
+
107
- End If
195
+ End Using
108
-
109
- Return View(test)
110
-
111
- End Function
112
196
 
113
197
  ```
114
198
 
115
199
 
116
200
 
117
-
118
-
119
-
120
-
121
- ※以下はTest.vbのファイルです。
122
-
123
- ```VisualBasic
124
-
125
-
126
-
127
-
128
-
129
- Imports System.ComponentModel.DataAnnotations
130
-
131
- Imports System.ComponentModel
132
-
133
-
134
-
135
- Public Class Test
136
-
137
-
138
-
139
- <Key()>
140
-
141
- <DisplayName("ID")>
142
-
143
- Public Property Id As String
144
-
145
-
146
-
147
- <DisplayName("時間")>
148
-
149
- Public Property Time As Integer
150
-
151
-
152
-
153
- End Class
154
-
155
- ```
156
-
157
-
158
-
159
- ※以下はCreate.vbhtmlのファイルです。(コメント欄参考用)
160
-
161
- ```VisualBasic
162
-
163
- @ModelType MvcApp.Test
164
-
165
-
166
-
167
- @Using (Html.BeginForm())
168
-
169
- @*「時間」用TextBox*@
170
-
171
- <div class="form-group">
172
-
173
- @Html.LabelFor(Function(model) model.Time, htmlAttributes:=New With {.class = "control-label col-md-2"})
174
-
175
- <div class="col-md-10">
176
-
177
- @Html.TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})
178
-
179
- </div>
180
-
181
- </div>
182
-
183
-
184
-
185
- @*「分」用TextBox*@
186
-
187
- <div class="form-group">
188
-
189
- @Html.LabelFor(Function(model) model.Time, htmlAttributes:=New With {.class = "control-label col-md-2"})
190
-
191
- <div class="col-md-10">
192
-
193
- @Html.TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})
194
-
195
- </div>
196
-
197
- </div>
198
-
199
- End Using
200
-
201
- ```
202
-
203
-
204
-
205
201
  ### 補足情報(FW/ツールのバージョンなど)
206
202
 
207
203
 

3

発生している問題・エラーメッセージの箇所の修正

2020/06/02 13:58

投稿

Eltk
Eltk

スコア51

test CHANGED
File without changes
test CHANGED
@@ -42,12 +42,20 @@
42
42
 
43
43
  ```
44
44
 
45
- 上記の実装を考えるにあたって、特に、下記の内容についてとっかかりがなく困っております。
45
+ 上記の実装を考えるにあたって、特に、下記の二点についてとっかかりがなく困っております。
46
46
 
47
47
 
48
48
 
49
49
  ①Modelで定義した1つのPropertyに対して、どのようにしてViewで2つのテキストボックスに分けるのか。
50
50
 
51
+ ②下記「該当のソースコード」の「TestsController.vb」において、Viewでのテキストボックスの値を結合する記述を書くのはどの箇所で、どのように書けば良いのか。
52
+
53
+
54
+
55
+
56
+
57
+ ①についてですが、
58
+
51
59
  「@TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})」
52
60
 
53
61
  のようなTextBoxForメソッドを2つ用意することを考えておりますが、
@@ -56,11 +64,11 @@
56
64
 
57
65
 
58
66
 
59
-
60
-
61
- 下記「該当のソースコード」の「TestsController.vb」いて、Viewのテキストボックスの値を結合る記述を書くのはどの箇所でどのように書けば良いのか。
67
+ ②にいてです
62
-
68
+
63
- (※各々のテキストボックスにidを付与し、Javascriptでテキストボックスの中身を取得、結合したら良いのかなとは考えています。ただ、その結合結果を、このCreateアクションにどうやって組み込ませれば良いのかがわかりません。)
69
+ 各々のテキストボックスに、Javascriptでテキストボックスの中身を取得、結合したら良いのかなとは考えています。
70
+
71
+ ただ、その結合結果を、このCreateアクションにどうやって組み込ませれば良いのかがわかりません。)
64
72
 
65
73
 
66
74
 

2

マークダウン記法に則り修正

2020/06/02 13:36

投稿

Eltk
Eltk

スコア51

test CHANGED
File without changes
test CHANGED
@@ -72,14 +72,14 @@
72
72
 
73
73
  ### 該当のソースコード
74
74
 
75
+ ※以下はTestsController.vbのファイルです。
76
+
77
+ ※今回の質問に必要だと思われる箇所以外は一部省略し、データ挿入時のCreateアクションのみを書いております。
78
+
75
79
 
76
80
 
77
81
  ```VisualBasic
78
82
 
79
- ※TestsController.vbのファイルです。
80
-
81
- ※今回の質問に必要だと思われる箇所以外は一部省略し、データ挿入時のCreateアクションのみを書いております。
82
-
83
83
 
84
84
 
85
85
  <HttpPost()>
@@ -106,9 +106,15 @@
106
106
 
107
107
 
108
108
 
109
+
110
+
111
+
112
+
113
+ ※以下はTest.vbのファイルです。
114
+
109
115
  ```VisualBasic
110
116
 
111
- ※Test.vbのファイルです。
117
+
112
118
 
113
119
 
114
120
 
@@ -142,11 +148,49 @@
142
148
 
143
149
 
144
150
 
145
-
151
+ ※以下はCreate.vbhtmlのファイルです。(コメント欄参考用)
152
+
146
-
153
+ ```VisualBasic
154
+
147
-
155
+ @ModelType MvcApp.Test
156
+
157
+
158
+
148
-
159
+ @Using (Html.BeginForm())
160
+
149
-
161
+ @*「時間」用TextBox*@
162
+
163
+ <div class="form-group">
164
+
165
+ @Html.LabelFor(Function(model) model.Time, htmlAttributes:=New With {.class = "control-label col-md-2"})
166
+
167
+ <div class="col-md-10">
168
+
169
+ @Html.TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})
170
+
171
+ </div>
172
+
173
+ </div>
174
+
175
+
176
+
177
+ @*「分」用TextBox*@
178
+
179
+ <div class="form-group">
180
+
181
+ @Html.LabelFor(Function(model) model.Time, htmlAttributes:=New With {.class = "control-label col-md-2"})
182
+
183
+ <div class="col-md-10">
184
+
185
+ @Html.TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})
186
+
187
+ </div>
188
+
189
+ </div>
190
+
191
+ End Using
192
+
193
+ ```
150
194
 
151
195
 
152
196
 

1

質問内容の修正

2020/06/02 12:55

投稿

Eltk
Eltk

スコア51

test CHANGED
File without changes
test CHANGED
@@ -2,21 +2,31 @@
2
2
 
3
3
 
4
4
 
5
- 1.Modelファイルのテーブル定義で、
6
-
7
- Public Property Time As Integer」のよう定義
5
+ ユーザーからのフォームでの入力を受け取って、TestsテーブルのTimeカラムに時間を登録したいのですが、入力時は「時と「分」二箇所を入力してもらい、DB登録時結合させたい」
8
6
 
9
7
 
10
8
 
11
- 2.Viewファイルの表示では、
12
9
 
13
- 「@TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})」
14
10
 
15
- ような記述を、2つ用意(時間用の入力ボックスと分用の入力ボックス)
11
+ 詳細は以下通りです。
16
12
 
17
13
 
18
14
 
15
+
16
+
17
+ 1.Modelファイルで
18
+
19
+ 「Public Property Time As Integer」と定義
20
+
21
+
22
+
23
+ 2.Viewファイルの表示ではTextBoxForを2つ用意(時間用と分用の入力ボックス)し、
24
+
25
+ ユーザーに「時」と「分」を二桁ずつ入力してもらう。
26
+
27
+
28
+
19
- 3.Controllerの、<HttpPost()>の方のCreateアクションを動かしてDBに挿入したいが、Viewファイルにてユーザーが入力したTextBoxの入力値を結合した後、
29
+ 3.ControllerではCreateアクションで入力値をDBに挿入したいが、ユーザーが入力した値を結合した後、
20
30
 
21
31
  DBへ挿入したい。
22
32
 
@@ -32,37 +42,27 @@
32
42
 
33
43
  ```
34
44
 
35
- 上記の実装を考えるにあたって、(全体的なコード上での記述の仕方もそうですが)特に、下記の内容についてとっかかりがなく詰まっております。
45
+ 上記の実装を考えるにあたって、特に、下記の内容についてとっかかりがなくっております。
36
46
 
37
47
 
38
48
 
39
- ・フォーム作成にあたって、今までModelで定義されたPropertyと入力フォームのテキストボックスは1対1対応が普通でしたで、
49
+ Modelで定義1つのPropertyに対して、どようにしてViewで2つのテキストボックスに分けるか。
40
50
 
51
+ 「@TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})」
52
+
41
- のようにして「時間」用のテキストボクスと「分」のテキストボックスに分けのか。
53
+ のようなTextBoxForメソドを2つ意すことを考えておりますが、
54
+
55
+ 「Funcrion(model) model.Time」の箇所はもちろん分割できないと思われますので、この箇所の書き方は検討が全くついておりません。
42
56
 
43
57
 
44
58
 
45
- ・下記「該当のソースコード」の「TestsController.vb」において、Viewでのテキストボックスの値を結合する記述を書くのはどの箇所で、どのように書けば良いのか。
46
-
47
- ※単なる文字列結合であれば、「+」演算子で結合した後、変数に代入し、その変数を使えば良さそうということまではイメージがつくのですが、
48
-
49
- 今回の場合、2つに分割したテキストボックスの値を取得し結合させるので、
50
-
51
- 各々のテキストボックスにidを付与し、Javascriptでテキストボックスの中身を取得、結合したら良いのかなとは考えています。
52
-
53
- ただ、その結合結果を、このCreateアクションにどうやって組み込ませれば良いのかがわかりません。
54
59
 
55
60
 
61
+ ②下記「該当のソースコード」の「TestsController.vb」において、Viewでのテキストボックスの値を結合する記述を書くのはどの箇所で、どのように書けば良いのか。
56
62
 
57
- ・Viewファイルテキストボックスの書き方
63
+ (※各々のテキストボックスにidを付与し、Javascriptでテキストボックスの中身を取得、結合したら良いのかなとは考えています。ただ、その結合結果を、このCreateアクションにどうやって組み込ませれば良いのかがわかりません。)
58
64
 
59
- 上記「実現したいこと」にて
60
65
 
61
- 「@TextBoxFor(Function(model) model.Time, New With {.htmlAttributes = New With {.class = "form-control"}})」
62
-
63
- のようなものを2つ用意することを考えておりますが、
64
-
65
- 「Funcrion(model) model.Time」の箇所はもちろん分割できないと思われますので、この箇所の書き方は検討が全くついておりません。
66
66
 
67
67
 
68
68