質問編集履歴
7
MVC4→MVC5
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
ASP.NET
|
1
|
+
ASP.NET MVC5でLINQ TO SQLクラスのリストデータを更新する方法
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
こんにちわ。
|
2
|
-
ASP.NET
|
2
|
+
ASP.NET MVC5でWeb勤務表を作成していますが、ビューで編集したデータをリストでコントロールにポストした後の処理で困っています。
|
3
3
|
Postで受け取ったリストでデータベースを更新したいのですが、どのようにコーディングしていいか分かりません。
|
4
4
|
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。<HttpPost()>のDim sv_product = **dc.TKintai**.Find(product.id)のところでエラーがでます。
|
5
5
|
Dim sv_product = dc.TKintai.Find(product.id)を書き換えればうまくいくと思いますが、どうしていいかわかりません。
|
6
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -153,40 +153,7 @@
|
|
153
153
|
overtime
|
154
154
|
</th>
|
155
155
|
</tr>
|
156
|
-
|
157
|
-
<%--<% For Each item In Model%>
|
158
156
|
|
159
|
-
<tr>
|
160
|
-
<td>
|
161
|
-
<%: item.id %>
|
162
|
-
</td>
|
163
|
-
<td>
|
164
|
-
<%: item.week %>
|
165
|
-
</td>
|
166
|
-
<td>
|
167
|
-
<%: item.open %>
|
168
|
-
</td>
|
169
|
-
<td>
|
170
|
-
<%: item.close %>
|
171
|
-
</td>
|
172
|
-
<td>
|
173
|
-
<%: item.rest %>
|
174
|
-
</td>
|
175
|
-
<td>
|
176
|
-
<%: item.situation %>
|
177
|
-
</td>
|
178
|
-
<td>
|
179
|
-
<%: item.remark %>
|
180
|
-
</td>
|
181
|
-
<td>
|
182
|
-
<%: item.worktime %>
|
183
|
-
</td>
|
184
|
-
<td>
|
185
|
-
<%: item.overtime %>
|
186
|
-
</td>
|
187
|
-
</tr>
|
188
|
-
|
189
|
-
<% Next%>--%>
|
190
157
|
<% For i = 0 To Model.Count - 1
|
191
158
|
|
192
159
|
Dim idx As Integer = i
|
5
タイトル変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
ASP.NET MVCでLINQ TO SQLクラスのデータを更新する方法
|
1
|
+
ASP.NET MVCでLINQ TO SQLクラスのリストデータを更新する方法
|
body
CHANGED
File without changes
|
4
タイトル間違い
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
LINQ TO SQLクラスの
|
1
|
+
ASP.NET MVCでLINQ TO SQLクラスのデータを更新する方法
|
body
CHANGED
File without changes
|
3
タグ変更
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
2
追加事項
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
こんにちわ。
|
2
2
|
ASP.NET MVCでWeb勤務表を作成していますが、ビューで編集したデータをリストでコントロールにポストした後の処理で困っています。
|
3
3
|
Postで受け取ったリストでデータベースを更新したいのですが、どのようにコーディングしていいか分かりません。
|
4
|
-
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。Dim sv_product = **dc.TKintai**.Find(product.id)のところでエラーがでます。
|
4
|
+
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。<HttpPost()>のDim sv_product = **dc.TKintai**.Find(product.id)のところでエラーがでます。
|
5
5
|
Dim sv_product = dc.TKintai.Find(product.id)を書き換えればうまくいくと思いますが、どうしていいかわかりません。
|
6
|
-
以下にコードを記します。
|
6
|
+
以下にコードを記します。一応モデルとビューも載せます。
|
7
7
|
|
8
8
|
コントローラ:
|
9
9
|
```
|
@@ -68,4 +68,179 @@
|
|
68
68
|
End Function
|
69
69
|
End Class
|
70
70
|
End Namespace
|
71
|
+
```
|
72
|
+
モデル:
|
73
|
+
```
|
74
|
+
Imports System.ComponentModel.DataAnnotations
|
75
|
+
Imports System.ComponentModel
|
76
|
+
|
77
|
+
Public Class HomeModels
|
78
|
+
Public Class Kintai
|
79
|
+
<Required()>
|
80
|
+
<DisplayName("日付")>
|
81
|
+
Public Property id As Integer
|
82
|
+
<Required()>
|
83
|
+
<DisplayName("曜日")>
|
84
|
+
Public Property week As String
|
85
|
+
<Required()>
|
86
|
+
<DisplayName("開始")>
|
87
|
+
Public Property open As Nullable(Of System.TimeSpan)
|
88
|
+
<Required()>
|
89
|
+
<DisplayName("終了")>
|
90
|
+
Public Property close As Nullable(Of System.TimeSpan)
|
91
|
+
<Required()>
|
92
|
+
<DisplayName("休憩")>
|
93
|
+
Public Property rest As Nullable(Of System.TimeSpan)
|
94
|
+
<Required()>
|
95
|
+
<DisplayName("状況")>
|
96
|
+
Public Property situation As String
|
97
|
+
<Required()>
|
98
|
+
<DisplayName("備考")>
|
99
|
+
Public Property remark As String
|
100
|
+
<Required()>
|
101
|
+
<DisplayName("所定時間")>
|
102
|
+
Public Property worktime As Nullable(Of System.TimeSpan)
|
103
|
+
<Required()>
|
104
|
+
<DisplayName("残業時間")>
|
105
|
+
Public Property overtime As Nullable(Of System.TimeSpan)
|
106
|
+
End Class
|
107
|
+
End Class
|
108
|
+
```
|
109
|
+
ビュー:
|
110
|
+
```
|
111
|
+
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(Of List (Of Kintai.HomeModels+Kintai))" %>
|
112
|
+
|
113
|
+
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
|
114
|
+
Index
|
115
|
+
</asp:Content>
|
116
|
+
|
117
|
+
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
|
118
|
+
|
119
|
+
<h2>Index</h2>
|
120
|
+
<% Using (Html.BeginForm())
|
121
|
+
Html.AntiForgeryToken()%>
|
122
|
+
<p>
|
123
|
+
<%: Html.ActionLink("Create New", "Create")%>
|
124
|
+
</p>
|
125
|
+
|
126
|
+
<table>
|
127
|
+
<tr>
|
128
|
+
<th>
|
129
|
+
id
|
130
|
+
</th>
|
131
|
+
<th>
|
132
|
+
week
|
133
|
+
</th>
|
134
|
+
<th>
|
135
|
+
open
|
136
|
+
</th>
|
137
|
+
<th>
|
138
|
+
close
|
139
|
+
</th>
|
140
|
+
<th>
|
141
|
+
rest
|
142
|
+
</th>
|
143
|
+
<th>
|
144
|
+
situation
|
145
|
+
</th>
|
146
|
+
<th>
|
147
|
+
remark
|
148
|
+
</th>
|
149
|
+
<th>
|
150
|
+
worktime
|
151
|
+
</th>
|
152
|
+
<th>
|
153
|
+
overtime
|
154
|
+
</th>
|
155
|
+
</tr>
|
156
|
+
|
157
|
+
<%--<% For Each item In Model%>
|
158
|
+
|
159
|
+
<tr>
|
160
|
+
<td>
|
161
|
+
<%: item.id %>
|
162
|
+
</td>
|
163
|
+
<td>
|
164
|
+
<%: item.week %>
|
165
|
+
</td>
|
166
|
+
<td>
|
167
|
+
<%: item.open %>
|
168
|
+
</td>
|
169
|
+
<td>
|
170
|
+
<%: item.close %>
|
171
|
+
</td>
|
172
|
+
<td>
|
173
|
+
<%: item.rest %>
|
174
|
+
</td>
|
175
|
+
<td>
|
176
|
+
<%: item.situation %>
|
177
|
+
</td>
|
178
|
+
<td>
|
179
|
+
<%: item.remark %>
|
180
|
+
</td>
|
181
|
+
<td>
|
182
|
+
<%: item.worktime %>
|
183
|
+
</td>
|
184
|
+
<td>
|
185
|
+
<%: item.overtime %>
|
186
|
+
</td>
|
187
|
+
</tr>
|
188
|
+
|
189
|
+
<% Next%>--%>
|
190
|
+
<% For i = 0 To Model.Count - 1
|
191
|
+
|
192
|
+
Dim idx As Integer = i
|
193
|
+
%>
|
194
|
+
|
195
|
+
<tr>
|
196
|
+
<td>
|
197
|
+
<%: Html.DisplayFor(Function(model) model(idx).id)%>
|
198
|
+
<%: Html.HiddenFor(Function(model) model(idx).id)%>
|
199
|
+
</td>
|
200
|
+
<td>
|
201
|
+
<%: Html.DisplayFor(Function(model) model(idx).week)%>
|
202
|
+
<%: Html.HiddenFor(Function(model) model(idx).week)%>
|
203
|
+
</td>
|
204
|
+
<td>
|
205
|
+
<%:Html.EditorFor(Function(model) model(idx).open, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
206
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).open, "", New With {.class = "text-danger"}) %>
|
207
|
+
</td>
|
208
|
+
<td>
|
209
|
+
<%:Html.EditorFor(Function(model) model(idx).close, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
210
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).close, "", New With {.class = "text-danger"})%>
|
211
|
+
</td>
|
212
|
+
<td>
|
213
|
+
<%:Html.EditorFor(Function(model) model(idx).rest, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
214
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).rest, "", New With {.class = "text-danger"})%>
|
215
|
+
</td>
|
216
|
+
<td>
|
217
|
+
<%: Html.DisplayFor(Function(model) model(idx).worktime)%>
|
218
|
+
<%: Html.HiddenFor(Function(model) model(idx).worktime)%>
|
219
|
+
</td>
|
220
|
+
<td>
|
221
|
+
<%: Html.DisplayFor(Function(model) model(idx).overtime)%>
|
222
|
+
<%: Html.HiddenFor(Function(model) model(idx).overtime)%>
|
223
|
+
</td>
|
224
|
+
<td>
|
225
|
+
<nobr>
|
226
|
+
<%:Html.ActionLink("定", "Edit", New With {.id = Model(idx).id})%>
|
227
|
+
<%:Html.ActionLink("前", "Edit", New With {.id = Model(idx).id})%>
|
228
|
+
</nobr>
|
229
|
+
</td>
|
230
|
+
<td>
|
231
|
+
<%:Html.EditorFor(Function(model) model(idx).remark, New With {.htmlAttributes = New With {.class = "form-control"}})%>
|
232
|
+
<%:Html.ValidationMessageFor(Function(model) model(idx).remark, "", New With {.class = "text-danger"})%>
|
233
|
+
</td>
|
234
|
+
</tr>
|
235
|
+
|
236
|
+
<% Next%>
|
237
|
+
</table>
|
238
|
+
<div Class="form-group">
|
239
|
+
<div Class="col-md-offset-2 col-md-10">
|
240
|
+
<input type="submit" value="Save" Class="btn btn-default" />
|
241
|
+
</div>
|
242
|
+
</div>
|
243
|
+
<% End Using%>
|
244
|
+
|
245
|
+
</asp:Content>
|
71
246
|
```
|
1
文法修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
こんにちわ。
|
2
2
|
ASP.NET MVCでWeb勤務表を作成していますが、ビューで編集したデータをリストでコントロールにポストした後の処理で困っています。
|
3
3
|
Postで受け取ったリストでデータベースを更新したいのですが、どのようにコーディングしていいか分かりません。
|
4
|
-
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。
|
4
|
+
以前Entitityで使ったときのコードをそのまま乗せてみましたが、「'TKintai' は 'System.Data.Linq.DataContext' のメンバーではありません。」というエラーがでます。Dim sv_product = **dc.TKintai**.Find(product.id)のところでエラーがでます。
|
5
5
|
Dim sv_product = dc.TKintai.Find(product.id)を書き換えればうまくいくと思いますが、どうしていいかわかりません。
|
6
6
|
以下にコードを記します。エラーが出るところを太字にしています。
|
7
7
|
|
@@ -52,7 +52,7 @@
|
|
52
52
|
Function Index(products As List(Of TKintai)) As ActionResult
|
53
53
|
|
54
54
|
For Each product In products
|
55
|
-
Dim sv_product =
|
55
|
+
Dim sv_product = dc.TKintai.Find(product.id)
|
56
56
|
sv_product.open = product.open
|
57
57
|
sv_product.close = product.close
|
58
58
|
sv_product.rest = product.rest
|