質問編集履歴
7
MVC4→MVC5
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ASP.NET MVCでLINQ TO SQLクラスのリストデータを更新する方法
|
1
|
+
ASP.NET MVC5でLINQ TO SQLクラスのリストデータを更新する方法
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
こんにちわ。
|
2
2
|
|
3
|
-
ASP.NET MVCでWeb勤務表を作成していますが、ビューで編集したデータをリストでコントロールにポストした後の処理で困っています。
|
3
|
+
ASP.NET MVC5でWeb勤務表を作成していますが、ビューで編集したデータをリストでコントロールにポストした後の処理で困っています。
|
4
4
|
|
5
5
|
Postで受け取ったリストでデータベースを更新したいのですが、どのようにコーディングしていいか分かりません。
|
6
6
|
|
6
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -308,65 +308,93 @@
|
|
308
308
|
|
309
309
|
</tr>
|
310
310
|
|
311
|
-
|
312
|
-
|
313
|
-
<%--<% For Each item In Model%>
|
314
|
-
|
315
311
|
|
316
312
|
|
313
|
+
<% For i = 0 To Model.Count - 1
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
Dim idx As Integer = i
|
318
|
+
|
319
|
+
%>
|
320
|
+
|
321
|
+
|
322
|
+
|
317
323
|
<tr>
|
318
324
|
|
319
325
|
<td>
|
320
326
|
|
321
|
-
<%: item.id
|
322
|
-
|
323
|
-
<
|
324
|
-
|
325
|
-
<td>
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
<
|
330
|
-
|
331
|
-
<td>
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
<
|
336
|
-
|
337
|
-
<td>
|
338
|
-
|
339
|
-
<%:
|
340
|
-
|
341
|
-
</td>
|
342
|
-
|
343
|
-
<td>
|
344
|
-
|
345
|
-
<%:
|
346
|
-
|
347
|
-
<
|
348
|
-
|
349
|
-
<td>
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
<
|
354
|
-
|
355
|
-
<td>
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
<
|
360
|
-
|
361
|
-
<td>
|
362
|
-
|
363
|
-
<%: item.worktime
|
364
|
-
|
365
|
-
</td>
|
366
|
-
|
367
|
-
<td>
|
368
|
-
|
369
|
-
<%: item.overtime
|
327
|
+
<%: Html.DisplayFor(Function(model) model(idx).id)%>
|
328
|
+
|
329
|
+
<%: Html.HiddenFor(Function(model) model(idx).id)%>
|
330
|
+
|
331
|
+
</td>
|
332
|
+
|
333
|
+
<td>
|
334
|
+
|
335
|
+
<%: Html.DisplayFor(Function(model) model(idx).week)%>
|
336
|
+
|
337
|
+
<%: Html.HiddenFor(Function(model) model(idx).week)%>
|
338
|
+
|
339
|
+
</td>
|
340
|
+
|
341
|
+
<td>
|
342
|
+
|
343
|
+
<%:Html.EditorFor(Function(model) model(idx).open, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
344
|
+
|
345
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).open, "", New With {.class = "text-danger"}) %>
|
346
|
+
|
347
|
+
</td>
|
348
|
+
|
349
|
+
<td>
|
350
|
+
|
351
|
+
<%:Html.EditorFor(Function(model) model(idx).close, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
352
|
+
|
353
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).close, "", New With {.class = "text-danger"})%>
|
354
|
+
|
355
|
+
</td>
|
356
|
+
|
357
|
+
<td>
|
358
|
+
|
359
|
+
<%:Html.EditorFor(Function(model) model(idx).rest, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
360
|
+
|
361
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).rest, "", New With {.class = "text-danger"})%>
|
362
|
+
|
363
|
+
</td>
|
364
|
+
|
365
|
+
<td>
|
366
|
+
|
367
|
+
<%: Html.DisplayFor(Function(model) model(idx).worktime)%>
|
368
|
+
|
369
|
+
<%: Html.HiddenFor(Function(model) model(idx).worktime)%>
|
370
|
+
|
371
|
+
</td>
|
372
|
+
|
373
|
+
<td>
|
374
|
+
|
375
|
+
<%: Html.DisplayFor(Function(model) model(idx).overtime)%>
|
376
|
+
|
377
|
+
<%: Html.HiddenFor(Function(model) model(idx).overtime)%>
|
378
|
+
|
379
|
+
</td>
|
380
|
+
|
381
|
+
<td>
|
382
|
+
|
383
|
+
<nobr>
|
384
|
+
|
385
|
+
<%:Html.ActionLink("定", "Edit", New With {.id = Model(idx).id})%>
|
386
|
+
|
387
|
+
<%:Html.ActionLink("前", "Edit", New With {.id = Model(idx).id})%>
|
388
|
+
|
389
|
+
</nobr>
|
390
|
+
|
391
|
+
</td>
|
392
|
+
|
393
|
+
<td>
|
394
|
+
|
395
|
+
<%:Html.EditorFor(Function(model) model(idx).remark, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
396
|
+
|
397
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).remark, "", New With {.class = "text-danger"})%>
|
370
398
|
|
371
399
|
</td>
|
372
400
|
|
@@ -374,100 +402,6 @@
|
|
374
402
|
|
375
403
|
|
376
404
|
|
377
|
-
<% Next%>--%>
|
378
|
-
|
379
|
-
<% For i = 0 To Model.Count - 1
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
Dim idx As Integer = i
|
384
|
-
|
385
|
-
%>
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
<tr>
|
390
|
-
|
391
|
-
<td>
|
392
|
-
|
393
|
-
<%: Html.DisplayFor(Function(model) model(idx).id)%>
|
394
|
-
|
395
|
-
<%: Html.HiddenFor(Function(model) model(idx).id)%>
|
396
|
-
|
397
|
-
</td>
|
398
|
-
|
399
|
-
<td>
|
400
|
-
|
401
|
-
<%: Html.DisplayFor(Function(model) model(idx).week)%>
|
402
|
-
|
403
|
-
<%: Html.HiddenFor(Function(model) model(idx).week)%>
|
404
|
-
|
405
|
-
</td>
|
406
|
-
|
407
|
-
<td>
|
408
|
-
|
409
|
-
<%:Html.EditorFor(Function(model) model(idx).open, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
410
|
-
|
411
|
-
<%:Html.ValidationMessageFor(Function(model) model(idx).open, "", New With {.class = "text-danger"}) %>
|
412
|
-
|
413
|
-
</td>
|
414
|
-
|
415
|
-
<td>
|
416
|
-
|
417
|
-
<%:Html.EditorFor(Function(model) model(idx).close, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
418
|
-
|
419
|
-
<%:Html.ValidationMessageFor(Function(model) model(idx).close, "", New With {.class = "text-danger"})%>
|
420
|
-
|
421
|
-
</td>
|
422
|
-
|
423
|
-
<td>
|
424
|
-
|
425
|
-
<%:Html.EditorFor(Function(model) model(idx).rest, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
426
|
-
|
427
|
-
<%:Html.ValidationMessageFor(Function(model) model(idx).rest, "", New With {.class = "text-danger"})%>
|
428
|
-
|
429
|
-
</td>
|
430
|
-
|
431
|
-
<td>
|
432
|
-
|
433
|
-
<%: Html.DisplayFor(Function(model) model(idx).worktime)%>
|
434
|
-
|
435
|
-
<%: Html.HiddenFor(Function(model) model(idx).worktime)%>
|
436
|
-
|
437
|
-
</td>
|
438
|
-
|
439
|
-
<td>
|
440
|
-
|
441
|
-
<%: Html.DisplayFor(Function(model) model(idx).overtime)%>
|
442
|
-
|
443
|
-
<%: Html.HiddenFor(Function(model) model(idx).overtime)%>
|
444
|
-
|
445
|
-
</td>
|
446
|
-
|
447
|
-
<td>
|
448
|
-
|
449
|
-
<nobr>
|
450
|
-
|
451
|
-
<%:Html.ActionLink("定", "Edit", New With {.id = Model(idx).id})%>
|
452
|
-
|
453
|
-
<%:Html.ActionLink("前", "Edit", New With {.id = Model(idx).id})%>
|
454
|
-
|
455
|
-
</nobr>
|
456
|
-
|
457
|
-
</td>
|
458
|
-
|
459
|
-
<td>
|
460
|
-
|
461
|
-
<%:Html.EditorFor(Function(model) model(idx).remark, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
462
|
-
|
463
|
-
<%:Html.ValidationMessageFor(Function(model) model(idx).remark, "", New With {.class = "text-danger"})%>
|
464
|
-
|
465
|
-
</td>
|
466
|
-
|
467
|
-
</tr>
|
468
|
-
|
469
|
-
|
470
|
-
|
471
405
|
<% Next%>
|
472
406
|
|
473
407
|
</table>
|
5
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ASP.NET MVCでLINQ TO SQLクラスのデータを更新する方法
|
1
|
+
ASP.NET MVCでLINQ TO SQLクラスのリストデータを更新する方法
|
test
CHANGED
File without changes
|
4
タイトル間違い
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
LINQ TO SQLクラスの
|
1
|
+
ASP.NET MVCでLINQ TO SQLクラスのデータを更新する方法
|
test
CHANGED
File without changes
|
3
タグ変更
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
追加事項
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
|
5
5
|
Postで受け取ったリストでデータベースを更新したいのですが、どのようにコーディングしていいか分かりません。
|
6
6
|
|
7
|
-
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。Dim sv_product = **dc.TKintai**.Find(product.id)のところでエラーがでます。
|
7
|
+
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。<HttpPost()>のDim sv_product = **dc.TKintai**.Find(product.id)のところでエラーがでます。
|
8
8
|
|
9
9
|
Dim sv_product = dc.TKintai.Find(product.id)を書き換えればうまくいくと思いますが、どうしていいかわかりません。
|
10
10
|
|
11
|
-
以下にコードを記します。
|
11
|
+
以下にコードを記します。一応モデルとビューも載せます。
|
12
12
|
|
13
13
|
|
14
14
|
|
@@ -139,3 +139,353 @@
|
|
139
139
|
End Namespace
|
140
140
|
|
141
141
|
```
|
142
|
+
|
143
|
+
モデル:
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
Imports System.ComponentModel.DataAnnotations
|
148
|
+
|
149
|
+
Imports System.ComponentModel
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
Public Class HomeModels
|
154
|
+
|
155
|
+
Public Class Kintai
|
156
|
+
|
157
|
+
<Required()>
|
158
|
+
|
159
|
+
<DisplayName("日付")>
|
160
|
+
|
161
|
+
Public Property id As Integer
|
162
|
+
|
163
|
+
<Required()>
|
164
|
+
|
165
|
+
<DisplayName("曜日")>
|
166
|
+
|
167
|
+
Public Property week As String
|
168
|
+
|
169
|
+
<Required()>
|
170
|
+
|
171
|
+
<DisplayName("開始")>
|
172
|
+
|
173
|
+
Public Property open As Nullable(Of System.TimeSpan)
|
174
|
+
|
175
|
+
<Required()>
|
176
|
+
|
177
|
+
<DisplayName("終了")>
|
178
|
+
|
179
|
+
Public Property close As Nullable(Of System.TimeSpan)
|
180
|
+
|
181
|
+
<Required()>
|
182
|
+
|
183
|
+
<DisplayName("休憩")>
|
184
|
+
|
185
|
+
Public Property rest As Nullable(Of System.TimeSpan)
|
186
|
+
|
187
|
+
<Required()>
|
188
|
+
|
189
|
+
<DisplayName("状況")>
|
190
|
+
|
191
|
+
Public Property situation As String
|
192
|
+
|
193
|
+
<Required()>
|
194
|
+
|
195
|
+
<DisplayName("備考")>
|
196
|
+
|
197
|
+
Public Property remark As String
|
198
|
+
|
199
|
+
<Required()>
|
200
|
+
|
201
|
+
<DisplayName("所定時間")>
|
202
|
+
|
203
|
+
Public Property worktime As Nullable(Of System.TimeSpan)
|
204
|
+
|
205
|
+
<Required()>
|
206
|
+
|
207
|
+
<DisplayName("残業時間")>
|
208
|
+
|
209
|
+
Public Property overtime As Nullable(Of System.TimeSpan)
|
210
|
+
|
211
|
+
End Class
|
212
|
+
|
213
|
+
End Class
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
ビュー:
|
218
|
+
|
219
|
+
```
|
220
|
+
|
221
|
+
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(Of List (Of Kintai.HomeModels+Kintai))" %>
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
|
226
|
+
|
227
|
+
Index
|
228
|
+
|
229
|
+
</asp:Content>
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
<h2>Index</h2>
|
238
|
+
|
239
|
+
<% Using (Html.BeginForm())
|
240
|
+
|
241
|
+
Html.AntiForgeryToken()%>
|
242
|
+
|
243
|
+
<p>
|
244
|
+
|
245
|
+
<%: Html.ActionLink("Create New", "Create")%>
|
246
|
+
|
247
|
+
</p>
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
<table>
|
252
|
+
|
253
|
+
<tr>
|
254
|
+
|
255
|
+
<th>
|
256
|
+
|
257
|
+
id
|
258
|
+
|
259
|
+
</th>
|
260
|
+
|
261
|
+
<th>
|
262
|
+
|
263
|
+
week
|
264
|
+
|
265
|
+
</th>
|
266
|
+
|
267
|
+
<th>
|
268
|
+
|
269
|
+
open
|
270
|
+
|
271
|
+
</th>
|
272
|
+
|
273
|
+
<th>
|
274
|
+
|
275
|
+
close
|
276
|
+
|
277
|
+
</th>
|
278
|
+
|
279
|
+
<th>
|
280
|
+
|
281
|
+
rest
|
282
|
+
|
283
|
+
</th>
|
284
|
+
|
285
|
+
<th>
|
286
|
+
|
287
|
+
situation
|
288
|
+
|
289
|
+
</th>
|
290
|
+
|
291
|
+
<th>
|
292
|
+
|
293
|
+
remark
|
294
|
+
|
295
|
+
</th>
|
296
|
+
|
297
|
+
<th>
|
298
|
+
|
299
|
+
worktime
|
300
|
+
|
301
|
+
</th>
|
302
|
+
|
303
|
+
<th>
|
304
|
+
|
305
|
+
overtime
|
306
|
+
|
307
|
+
</th>
|
308
|
+
|
309
|
+
</tr>
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
<%--<% For Each item In Model%>
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
<tr>
|
318
|
+
|
319
|
+
<td>
|
320
|
+
|
321
|
+
<%: item.id %>
|
322
|
+
|
323
|
+
</td>
|
324
|
+
|
325
|
+
<td>
|
326
|
+
|
327
|
+
<%: item.week %>
|
328
|
+
|
329
|
+
</td>
|
330
|
+
|
331
|
+
<td>
|
332
|
+
|
333
|
+
<%: item.open %>
|
334
|
+
|
335
|
+
</td>
|
336
|
+
|
337
|
+
<td>
|
338
|
+
|
339
|
+
<%: item.close %>
|
340
|
+
|
341
|
+
</td>
|
342
|
+
|
343
|
+
<td>
|
344
|
+
|
345
|
+
<%: item.rest %>
|
346
|
+
|
347
|
+
</td>
|
348
|
+
|
349
|
+
<td>
|
350
|
+
|
351
|
+
<%: item.situation %>
|
352
|
+
|
353
|
+
</td>
|
354
|
+
|
355
|
+
<td>
|
356
|
+
|
357
|
+
<%: item.remark %>
|
358
|
+
|
359
|
+
</td>
|
360
|
+
|
361
|
+
<td>
|
362
|
+
|
363
|
+
<%: item.worktime %>
|
364
|
+
|
365
|
+
</td>
|
366
|
+
|
367
|
+
<td>
|
368
|
+
|
369
|
+
<%: item.overtime %>
|
370
|
+
|
371
|
+
</td>
|
372
|
+
|
373
|
+
</tr>
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
<% Next%>--%>
|
378
|
+
|
379
|
+
<% For i = 0 To Model.Count - 1
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
Dim idx As Integer = i
|
384
|
+
|
385
|
+
%>
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
<tr>
|
390
|
+
|
391
|
+
<td>
|
392
|
+
|
393
|
+
<%: Html.DisplayFor(Function(model) model(idx).id)%>
|
394
|
+
|
395
|
+
<%: Html.HiddenFor(Function(model) model(idx).id)%>
|
396
|
+
|
397
|
+
</td>
|
398
|
+
|
399
|
+
<td>
|
400
|
+
|
401
|
+
<%: Html.DisplayFor(Function(model) model(idx).week)%>
|
402
|
+
|
403
|
+
<%: Html.HiddenFor(Function(model) model(idx).week)%>
|
404
|
+
|
405
|
+
</td>
|
406
|
+
|
407
|
+
<td>
|
408
|
+
|
409
|
+
<%:Html.EditorFor(Function(model) model(idx).open, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
410
|
+
|
411
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).open, "", New With {.class = "text-danger"}) %>
|
412
|
+
|
413
|
+
</td>
|
414
|
+
|
415
|
+
<td>
|
416
|
+
|
417
|
+
<%:Html.EditorFor(Function(model) model(idx).close, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
418
|
+
|
419
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).close, "", New With {.class = "text-danger"})%>
|
420
|
+
|
421
|
+
</td>
|
422
|
+
|
423
|
+
<td>
|
424
|
+
|
425
|
+
<%:Html.EditorFor(Function(model) model(idx).rest, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
426
|
+
|
427
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).rest, "", New With {.class = "text-danger"})%>
|
428
|
+
|
429
|
+
</td>
|
430
|
+
|
431
|
+
<td>
|
432
|
+
|
433
|
+
<%: Html.DisplayFor(Function(model) model(idx).worktime)%>
|
434
|
+
|
435
|
+
<%: Html.HiddenFor(Function(model) model(idx).worktime)%>
|
436
|
+
|
437
|
+
</td>
|
438
|
+
|
439
|
+
<td>
|
440
|
+
|
441
|
+
<%: Html.DisplayFor(Function(model) model(idx).overtime)%>
|
442
|
+
|
443
|
+
<%: Html.HiddenFor(Function(model) model(idx).overtime)%>
|
444
|
+
|
445
|
+
</td>
|
446
|
+
|
447
|
+
<td>
|
448
|
+
|
449
|
+
<nobr>
|
450
|
+
|
451
|
+
<%:Html.ActionLink("定", "Edit", New With {.id = Model(idx).id})%>
|
452
|
+
|
453
|
+
<%:Html.ActionLink("前", "Edit", New With {.id = Model(idx).id})%>
|
454
|
+
|
455
|
+
</nobr>
|
456
|
+
|
457
|
+
</td>
|
458
|
+
|
459
|
+
<td>
|
460
|
+
|
461
|
+
<%:Html.EditorFor(Function(model) model(idx).remark, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
462
|
+
|
463
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).remark, "", New With {.class = "text-danger"})%>
|
464
|
+
|
465
|
+
</td>
|
466
|
+
|
467
|
+
</tr>
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
<% Next%>
|
472
|
+
|
473
|
+
</table>
|
474
|
+
|
475
|
+
<div Class="form-group">
|
476
|
+
|
477
|
+
<div Class="col-md-offset-2 col-md-10">
|
478
|
+
|
479
|
+
<input type="submit" value="Save" Class="btn btn-default" />
|
480
|
+
|
481
|
+
</div>
|
482
|
+
|
483
|
+
</div>
|
484
|
+
|
485
|
+
<% End Using%>
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
</asp:Content>
|
490
|
+
|
491
|
+
```
|
1
文法修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Postで受け取ったリストでデータベースを更新したいのですが、どのようにコーディングしていいか分かりません。
|
6
6
|
|
7
|
-
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。
|
7
|
+
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。Dim sv_product = **dc.TKintai**.Find(product.id)のところでエラーがでます。
|
8
8
|
|
9
9
|
Dim sv_product = dc.TKintai.Find(product.id)を書き換えればうまくいくと思いますが、どうしていいかわかりません。
|
10
10
|
|
@@ -106,7 +106,7 @@
|
|
106
106
|
|
107
107
|
For Each product In products
|
108
108
|
|
109
|
-
Dim sv_product =
|
109
|
+
Dim sv_product = dc.TKintai.Find(product.id)
|
110
110
|
|
111
111
|
sv_product.open = product.open
|
112
112
|
|