質問編集履歴

6

MVC4→MVC5

2019/01/08 01:49

投稿

blackdifferent
blackdifferent

スコア25

test CHANGED
@@ -1 +1 @@
1
- ASP.NET MVCでリストをビューからコントローラへ渡す方法
1
+ ASP.NET MVC5でリストをビューからコントローラへ渡す方法
test CHANGED
File without changes

5

書式の改善

2019/01/08 01:49

投稿

blackdifferent
blackdifferent

スコア25

test CHANGED
File without changes
test CHANGED
@@ -24,12 +24,10 @@
24
24
 
25
25
  MODEL:
26
26
 
27
-
27
+ ```
28
28
 
29
29
  namespace MvcShopping.Models
30
30
 
31
- '''
32
-
33
31
  {
34
32
 
35
33
 
@@ -52,16 +50,16 @@
52
50
 
53
51
  }
54
52
 
55
- '''
53
+ ```
56
54
 
57
55
 
58
56
 
59
57
  CONTROLLER:
60
58
 
59
+ ```
60
+
61
61
  namespace MvcShopping.Controllers
62
62
 
63
- '''
64
-
65
63
  {
66
64
 
67
65
  public class KintaiController : Controller
@@ -152,12 +150,14 @@
152
150
 
153
151
  }
154
152
 
155
- '''
153
+ ```
156
154
 
157
155
 
158
156
 
159
157
  View:
160
158
 
159
+ ```
160
+
161
161
  <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcShopping.Models.TKintai>>" %>
162
162
 
163
163
 
@@ -168,7 +168,7 @@
168
168
 
169
169
  </asp:Content>
170
170
 
171
- '''
171
+
172
172
 
173
173
  <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
174
174
 
@@ -392,7 +392,7 @@
392
392
 
393
393
  </asp:Content>
394
394
 
395
- '''
395
+ ```
396
396
 
397
397
 
398
398
 

4

書式の改善

2018/11/28 00:00

投稿

blackdifferent
blackdifferent

スコア25

test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,9 @@
26
26
 
27
27
 
28
28
 
29
- '''namespace MvcShopping.Models
29
+ namespace MvcShopping.Models
30
+
31
+ '''
30
32
 
31
33
  {
32
34
 
@@ -56,7 +58,9 @@
56
58
 
57
59
  CONTROLLER:
58
60
 
59
- '''namespace MvcShopping.Controllers
61
+ namespace MvcShopping.Controllers
62
+
63
+ '''
60
64
 
61
65
  {
62
66
 
@@ -158,12 +162,14 @@
158
162
 
159
163
 
160
164
 
161
- '''<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
165
+ <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
162
166
 
163
167
  Index
164
168
 
165
169
  </asp:Content>
166
170
 
171
+ '''
172
+
167
173
  <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
168
174
 
169
175
  <form id="form1" runat="server">

3

書式の改善

2018/11/27 14:43

投稿

blackdifferent
blackdifferent

スコア25

test CHANGED
File without changes
test CHANGED
@@ -26,374 +26,368 @@
26
26
 
27
27
 
28
28
 
29
- namespace MvcShopping.Models
29
+ '''namespace MvcShopping.Models
30
30
 
31
31
  {
32
32
 
33
+
34
+
35
+ /// <summary>
36
+
37
+ /// 勤務表情報のモデルクラス
38
+
39
+ /// </summary>
40
+
41
+ public class KintaiModel
42
+
43
+ {
44
+
45
+ //勤務表リスト
46
+
47
+ public IQueryable<TKintai> Kintais { get; set; }
48
+
49
+ }
50
+
51
+ }
52
+
33
53
  '''
34
54
 
35
- /// <summary>
55
+
36
-
56
+
37
- /// 勤務表情報のモデルクラス
57
+ CONTROLLER:
38
-
58
+
39
- /// </summary>
59
+ '''namespace MvcShopping.Controllers
60
+
40
-
61
+ {
62
+
41
- public class KintaiModel
63
+ public class KintaiController : Controller
42
64
 
43
65
  {
44
66
 
67
+
68
+
45
- //勤務表リスト
69
+ //
70
+
46
-
71
+ // GET: /Kintai/
72
+
73
+
74
+
75
+ public ActionResult Index()
76
+
77
+ {
78
+
79
+ // web.config から接続文字列を取得
80
+
81
+ string cnstr = ConfigurationManager.ConnectionStrings[
82
+
83
+ "mvcdbConnectionString"].ConnectionString;
84
+
85
+
86
+
87
+ // データベースに接続する
88
+
89
+ DataContext dc = new DataContext(cnstr);
90
+
91
+ // 商品一覧を取得
92
+
47
- public IQueryable<TKintai> Kintais { get; set; }
93
+ var list = from p in dc.GetTable<TKintai>()
94
+
48
-
95
+ select p;
96
+
97
+
98
+
99
+ return View(list);
100
+
49
- }
101
+ }
102
+
103
+ //
104
+
105
+ // POST: /Admin/Edit/5
106
+
107
+
108
+
109
+ [HttpPost]
110
+
111
+ public ActionResult Index(KintaiModel kintai)
112
+
113
+ {
114
+
115
+ try
116
+
117
+ {
118
+
119
+ // web.config から接続文字列を取得
120
+
121
+ string cnstr = ConfigurationManager.ConnectionStrings[
122
+
123
+ "mvcdbConnectionString"].ConnectionString;
124
+
125
+ // データベースに接続する
126
+
127
+ DataContext dc = new DataContext(cnstr);
128
+
129
+ var list = from p in dc.GetTable<TKintai>()
130
+
131
+ select p;
132
+
133
+ return RedirectToAction("Index");
134
+
135
+ }
136
+
137
+ catch
138
+
139
+ {
140
+
141
+ return View();
142
+
143
+ }
144
+
145
+ }
146
+
147
+ }
148
+
149
+ }
50
150
 
51
151
  '''
52
152
 
153
+
154
+
53
- }
155
+ View:
156
+
54
-
157
+ <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcShopping.Models.TKintai>>" %>
158
+
159
+
160
+
55
-
161
+ '''<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
162
+
56
-
163
+ Index
164
+
57
-
165
+ </asp:Content>
166
+
58
-
167
+ <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
168
+
169
+ <form id="form1" runat="server">
170
+
59
- CONTROLLER:
171
+ <h2>
172
+
173
+ Index</h2>
174
+
175
+ <% using (Html.BeginForm())
176
+
177
+ {%>
178
+
179
+ <%: Html.ValidationSummary(true) %>
180
+
181
+ <fieldset>
182
+
183
+ <legend>Fields</legend>
184
+
185
+ <table>
186
+
187
+ <tr>
188
+
189
+ <th>
190
+
191
+ id
192
+
193
+ </th>
194
+
195
+ <th>
196
+
197
+ week
198
+
199
+ </th>
200
+
201
+ <th>
202
+
203
+ open
204
+
205
+ </th>
206
+
207
+ <th>
208
+
209
+ close
210
+
211
+ </th>
212
+
213
+ <th>
214
+
215
+ rest
216
+
217
+ </th>
218
+
219
+ <th>
220
+
221
+ worktime
222
+
223
+ </th>
224
+
225
+ <th>
226
+
227
+ overtime
228
+
229
+ </th>
230
+
231
+ <th>
232
+
233
+ situation
234
+
235
+ </th>
236
+
237
+ <th>
238
+
239
+ remark
240
+
241
+ </th>
242
+
243
+ </tr>
244
+
245
+ <%
246
+
247
+ foreach (var item in Model)
248
+
249
+ { %>
250
+
251
+ <tr>
252
+
253
+ <td>
254
+
255
+ <div class="editor-field">
256
+
257
+ <%: Html.TextBoxFor(model => item.id, new { style = "width:60px" })%>
258
+
259
+ <%: Html.ValidationMessageFor(model => item.id) %>
260
+
261
+ </div>
262
+
263
+ <%--<div class="display-field">
264
+
265
+ <%: item.id %></div>--%>
266
+
267
+ </td>
268
+
269
+ <td>
270
+
271
+ <div class="editor-field">
272
+
273
+ <%: Html.TextBoxFor(model => item.week, new { style = "width:60px" })%>
274
+
275
+ <%: Html.ValidationMessageFor(model => item.week) %>
276
+
277
+ </div>
278
+
279
+ <%-- <div class="display-field">
280
+
281
+ <%: item.week %></div>--%>
282
+
283
+ </td>
284
+
285
+ <td>
286
+
287
+ <div class="editor-field">
288
+
289
+ <%: Html.TextBoxFor(model => item.open, new { style = "width:60px" })%>
290
+
291
+ <%: Html.ValidationMessageFor(model => item.open) %>
292
+
293
+ </div>
294
+
295
+ </td>
296
+
297
+ <td>
298
+
299
+ <div class="editor-field">
300
+
301
+ <%: Html.TextBoxFor(model => item.close, new { style = "width:60px" })%>
302
+
303
+ <%: Html.ValidationMessageFor(model => item.close) %>
304
+
305
+ </div>
306
+
307
+ </td>
308
+
309
+ <td>
310
+
311
+ <div class="editor-field">
312
+
313
+ <%: Html.TextBoxFor(model => item.rest, new { style = "width:60px" })%>
314
+
315
+ <%: Html.ValidationMessageFor(model => item.rest) %>
316
+
317
+ </div>
318
+
319
+ </td>
320
+
321
+ <td>
322
+
323
+ <div class="editor-field">
324
+
325
+ <%: Html.TextBoxFor(model => item.worktime, new { style = "width:60px" })%>
326
+
327
+ <%: Html.ValidationMessageFor(model => item.worktime) %>
328
+
329
+ </div>
330
+
331
+ </td>
332
+
333
+ <td>
334
+
335
+ <div class="editor-field">
336
+
337
+ <%: Html.TextBoxFor(model => item.overtime, new { style = "width:60px" })%>
338
+
339
+ <%: Html.ValidationMessageFor(model => item.overtime) %>
340
+
341
+ </div>
342
+
343
+ </td>
344
+
345
+ <td>
346
+
347
+ <div class="editor-field">
348
+
349
+ <%: Html.TextBoxFor(model => item.situation, new { style = "width:60px" })%>
350
+
351
+ <%: Html.ValidationMessageFor(model => item.situation) %>
352
+
353
+ </div>
354
+
355
+ </td>
356
+
357
+ <td>
358
+
359
+ <div class="editor-field">
360
+
361
+ <%: Html.TextBoxFor(model => item.remark, new { style = "width:80px" })%>
362
+
363
+ <%: Html.ValidationMessageFor(model => item.remark) %>
364
+
365
+ </div>
366
+
367
+ </td>
368
+
369
+ </tr>
370
+
371
+ <% } %>
372
+
373
+ </table>
374
+
375
+ <p>
376
+
377
+ <input type="submit" value="更新" />
378
+
379
+ </p>
380
+
381
+ </fieldset>
382
+
383
+ <% } %>
384
+
385
+ </form>
386
+
387
+ </asp:Content>
60
388
 
61
389
  '''
62
390
 
63
- namespace MvcShopping.Controllers
64
-
65
- {
66
-
67
- public class KintaiController : Controller
68
-
69
- {
70
-
71
-
72
-
73
- //
74
-
75
- // GET: /Kintai/
76
-
77
-
78
-
79
- public ActionResult Index()
80
-
81
- {
82
-
83
- // web.config から接続文字列を取得
84
-
85
- string cnstr = ConfigurationManager.ConnectionStrings[
86
-
87
- "mvcdbConnectionString"].ConnectionString;
88
-
89
-
90
-
91
- // データベースに接続する
92
-
93
- DataContext dc = new DataContext(cnstr);
94
-
95
- // 商品一覧を取得
96
-
97
- var list = from p in dc.GetTable<TKintai>()
98
-
99
- select p;
100
-
101
-
102
-
103
- return View(list);
104
-
105
- }
106
-
107
- //
108
-
109
- // POST: /Admin/Edit/5
110
-
111
-
112
-
113
- [HttpPost]
114
-
115
- public ActionResult Index(KintaiModel kintai)
116
-
117
- {
118
-
119
- try
120
-
121
- {
122
-
123
- // web.config から接続文字列を取得
124
-
125
- string cnstr = ConfigurationManager.ConnectionStrings[
126
-
127
- "mvcdbConnectionString"].ConnectionString;
128
-
129
- // データベースに接続する
130
-
131
- DataContext dc = new DataContext(cnstr);
132
-
133
- var list = from p in dc.GetTable<TKintai>()
134
-
135
- select p;
136
-
137
- return RedirectToAction("Index");
138
-
139
- }
140
-
141
- catch
142
-
143
- {
144
-
145
- return View();
146
-
147
- }
148
-
149
- }
150
-
151
- }
152
-
153
- }
154
-
155
- '''
156
-
157
-
158
-
159
- View:
160
-
161
- '''
162
-
163
- <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcShopping.Models.TKintai>>" %>
164
-
165
-
166
-
167
- <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
168
-
169
- Index
170
-
171
- </asp:Content>
172
-
173
- <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
174
-
175
- <form id="form1" runat="server">
176
-
177
- <h2>
178
-
179
- Index</h2>
180
-
181
- <% using (Html.BeginForm())
182
-
183
- {%>
184
-
185
- <%: Html.ValidationSummary(true) %>
186
-
187
- <fieldset>
188
-
189
- <legend>Fields</legend>
190
-
191
- <table>
192
-
193
- <tr>
194
-
195
- <th>
196
-
197
- id
198
-
199
- </th>
200
-
201
- <th>
202
-
203
- week
204
-
205
- </th>
206
-
207
- <th>
208
-
209
- open
210
-
211
- </th>
212
-
213
- <th>
214
-
215
- close
216
-
217
- </th>
218
-
219
- <th>
220
-
221
- rest
222
-
223
- </th>
224
-
225
- <th>
226
-
227
- worktime
228
-
229
- </th>
230
-
231
- <th>
232
-
233
- overtime
234
-
235
- </th>
236
-
237
- <th>
238
-
239
- situation
240
-
241
- </th>
242
-
243
- <th>
244
-
245
- remark
246
-
247
- </th>
248
-
249
- </tr>
250
-
251
- <%
252
-
253
- foreach (var item in Model)
254
-
255
- { %>
256
-
257
- <tr>
258
-
259
- <td>
260
-
261
- <div class="editor-field">
262
-
263
- <%: Html.TextBoxFor(model => item.id, new { style = "width:60px" })%>
264
-
265
- <%: Html.ValidationMessageFor(model => item.id) %>
266
-
267
- </div>
268
-
269
- <%--<div class="display-field">
270
-
271
- <%: item.id %></div>--%>
272
-
273
- </td>
274
-
275
- <td>
276
-
277
- <div class="editor-field">
278
-
279
- <%: Html.TextBoxFor(model => item.week, new { style = "width:60px" })%>
280
-
281
- <%: Html.ValidationMessageFor(model => item.week) %>
282
-
283
- </div>
284
-
285
- <%-- <div class="display-field">
286
-
287
- <%: item.week %></div>--%>
288
-
289
- </td>
290
-
291
- <td>
292
-
293
- <div class="editor-field">
294
-
295
- <%: Html.TextBoxFor(model => item.open, new { style = "width:60px" })%>
296
-
297
- <%: Html.ValidationMessageFor(model => item.open) %>
298
-
299
- </div>
300
-
301
- </td>
302
-
303
- <td>
304
-
305
- <div class="editor-field">
306
-
307
- <%: Html.TextBoxFor(model => item.close, new { style = "width:60px" })%>
308
-
309
- <%: Html.ValidationMessageFor(model => item.close) %>
310
-
311
- </div>
312
-
313
- </td>
314
-
315
- <td>
316
-
317
- <div class="editor-field">
318
-
319
- <%: Html.TextBoxFor(model => item.rest, new { style = "width:60px" })%>
320
-
321
- <%: Html.ValidationMessageFor(model => item.rest) %>
322
-
323
- </div>
324
-
325
- </td>
326
-
327
- <td>
328
-
329
- <div class="editor-field">
330
-
331
- <%: Html.TextBoxFor(model => item.worktime, new { style = "width:60px" })%>
332
-
333
- <%: Html.ValidationMessageFor(model => item.worktime) %>
334
-
335
- </div>
336
-
337
- </td>
338
-
339
- <td>
340
-
341
- <div class="editor-field">
342
-
343
- <%: Html.TextBoxFor(model => item.overtime, new { style = "width:60px" })%>
344
-
345
- <%: Html.ValidationMessageFor(model => item.overtime) %>
346
-
347
- </div>
348
-
349
- </td>
350
-
351
- <td>
352
-
353
- <div class="editor-field">
354
-
355
- <%: Html.TextBoxFor(model => item.situation, new { style = "width:60px" })%>
356
-
357
- <%: Html.ValidationMessageFor(model => item.situation) %>
358
-
359
- </div>
360
-
361
- </td>
362
-
363
- <td>
364
-
365
- <div class="editor-field">
366
-
367
- <%: Html.TextBoxFor(model => item.remark, new { style = "width:80px" })%>
368
-
369
- <%: Html.ValidationMessageFor(model => item.remark) %>
370
-
371
- </div>
372
-
373
- </td>
374
-
375
- </tr>
376
-
377
- <% } %>
378
-
379
- </table>
380
-
381
- <p>
382
-
383
- <input type="submit" value="更新" />
384
-
385
- </p>
386
-
387
- </fieldset>
388
-
389
- <% } %>
390
-
391
- </form>
392
-
393
- </asp:Content>
394
-
395
- '''
396
-
397
391
 
398
392
 
399
393
  ### 試したこと

2

書式の改善

2018/11/27 14:39

投稿

blackdifferent
blackdifferent

スコア25

test CHANGED
File without changes
test CHANGED
@@ -24,12 +24,14 @@
24
24
 
25
25
  MODEL:
26
26
 
27
- '''
27
+
28
28
 
29
29
  namespace MvcShopping.Models
30
30
 
31
31
  {
32
32
 
33
+ '''
34
+
33
35
  /// <summary>
34
36
 
35
37
  /// 勤務表情報のモデルクラス
@@ -46,9 +48,11 @@
46
48
 
47
49
  }
48
50
 
51
+ '''
52
+
49
53
  }
50
54
 
51
- '''
55
+
52
56
 
53
57
 
54
58
 

1

書式の改善

2018/11/27 14:36

投稿

blackdifferent
blackdifferent

スコア25

test CHANGED
File without changes
test CHANGED
@@ -24,6 +24,8 @@
24
24
 
25
25
  MODEL:
26
26
 
27
+ '''
28
+
27
29
  namespace MvcShopping.Models
28
30
 
29
31
  {
@@ -46,10 +48,14 @@
46
48
 
47
49
  }
48
50
 
51
+ '''
52
+
49
53
 
50
54
 
51
55
  CONTROLLER:
52
56
 
57
+ '''
58
+
53
59
  namespace MvcShopping.Controllers
54
60
 
55
61
  {
@@ -142,10 +148,14 @@
142
148
 
143
149
  }
144
150
 
151
+ '''
152
+
145
153
 
146
154
 
147
155
  View:
148
156
 
157
+ '''
158
+
149
159
  <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcShopping.Models.TKintai>>" %>
150
160
 
151
161
 
@@ -378,7 +388,7 @@
378
388
 
379
389
  </asp:Content>
380
390
 
381
-
391
+ '''
382
392
 
383
393
 
384
394