質問編集履歴
3
情報の削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,8 +34,6 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
![イメージ説明](f08ad8c48bf0d5e34d24cc7bcba0a097.png)!
|
38
|
-
|
39
37
|
|
40
38
|
|
41
39
|
|
@@ -82,7 +80,7 @@
|
|
82
80
|
|
83
81
|
[ValidateAntiForgeryToken]
|
84
82
|
|
85
|
-
public ActionResult Create([Bind(Include = "Id,
|
83
|
+
public ActionResult Create([Bind(Include = "Id,")] Responses responses)
|
86
84
|
|
87
85
|
{
|
88
86
|
|
@@ -170,15 +168,25 @@
|
|
170
168
|
|
171
169
|
|
172
170
|
|
171
|
+
|
172
|
+
|
173
|
+
</div>
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
173
181
|
<div class="form-group">
|
174
182
|
|
175
|
-
@Html.LabelFor(model => model.
|
183
|
+
@Html.LabelFor(model => model.Contents, htmlAttributes: new { @class = "control-label col-md-2" })
|
176
184
|
|
177
185
|
<div class="col-md-10">
|
178
186
|
|
179
|
-
@Html.
|
187
|
+
@Html.EditorFor(model => model.Contents, new { htmlAttributes = new { @class = "form-control" } })
|
180
|
-
|
188
|
+
|
181
|
-
@Html.ValidationMessageFor(model => model.
|
189
|
+
@Html.ValidationMessageFor(model => model.Contents, "", new { @class = "text-danger" })
|
182
190
|
|
183
191
|
</div>
|
184
192
|
|
@@ -186,72 +194,40 @@
|
|
186
194
|
|
187
195
|
|
188
196
|
|
197
|
+
|
198
|
+
|
189
199
|
<div class="form-group">
|
190
200
|
|
191
|
-
@Html.LabelFor(model => model.
|
201
|
+
@Html.LabelFor(model => model.ResOwnerId, "レスの記入者", htmlAttributes: new { @class = "control-label col-md-2" })
|
192
202
|
|
193
203
|
<div class="col-md-10">
|
194
204
|
|
205
|
+
|
206
|
+
|
195
|
-
|
207
|
+
@Html.DropDownList("ResOwnerId", null, htmlAttributes: new { @class = "form-control" })
|
196
|
-
|
208
|
+
|
197
|
-
|
209
|
+
@Html.ValidationMessageFor(model => model.ResOwnerId, "", new { @class = "text-danger" })
|
210
|
+
|
211
|
+
|
198
212
|
|
199
213
|
</div>
|
200
214
|
|
201
215
|
</div>
|
202
216
|
|
217
|
+
|
218
|
+
|
203
219
|
|
204
220
|
|
205
221
|
<div class="form-group">
|
206
222
|
|
207
|
-
@Html.LabelFor(model => model.Contents, htmlAttributes: new { @class = "control-label col-md-2" })
|
208
|
-
|
209
|
-
<div class="col-md-10">
|
223
|
+
<div class="col-md-offset-2 col-md-10">
|
210
|
-
|
211
|
-
|
224
|
+
|
212
|
-
|
213
|
-
|
225
|
+
<input type="submit" value="Create" class="btn btn-default" />
|
214
226
|
|
215
227
|
</div>
|
216
228
|
|
217
229
|
</div>
|
218
230
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
<div class="form-group">
|
224
|
-
|
225
|
-
@Html.LabelFor(model => model.ResOwnerId, "レスの記入者", htmlAttributes: new { @class = "control-label col-md-2" })
|
226
|
-
|
227
|
-
<div class="col-md-10">
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
@Html.DropDownList("ResOwnerId", null, htmlAttributes: new { @class = "form-control" })
|
232
|
-
|
233
|
-
@Html.ValidationMessageFor(model => model.ResOwnerId, "", new { @class = "text-danger" })
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
</div>
|
238
|
-
|
239
|
-
</div>
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
<div class="form-group">
|
246
|
-
|
247
|
-
<div class="col-md-offset-2 col-md-10">
|
248
|
-
|
249
|
-
<input type="submit" value="Create" class="btn btn-default" />
|
250
|
-
|
251
|
-
</div>
|
252
|
-
|
253
|
-
</div>
|
254
|
-
|
255
231
|
</div>
|
256
232
|
|
257
233
|
}
|
@@ -276,146 +252,46 @@
|
|
276
252
|
|
277
253
|
```
|
278
254
|
|
255
|
+
### 試したこと
|
256
|
+
|
257
|
+
|
258
|
+
|
279
|
-
|
259
|
+
(1)
|
260
|
+
|
261
|
+
Controllerを次のように書き換えたところ、次の画像のようにViewで表示されるDropDownListの中身がChar型になってしまいます。
|
262
|
+
|
263
|
+
return contentを用いてidとnameを表示した時にはハッシュ値のパスとユーザー名が表示できたのでidとnameには問題がないのではと考えています
|
264
|
+
|
265
|
+
(idとnameにIdentityの情報を格納し、Viewbag.ResOwnerId の値をコメントアウトしている行からその次の行のように書き換えました)
|
280
266
|
|
281
267
|
```c#
|
282
268
|
|
283
|
-
|
269
|
+
// GET: Responses/Create
|
284
|
-
|
285
|
-
|
270
|
+
|
286
|
-
|
287
|
-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
|
288
|
-
|
289
|
-
public Res
|
271
|
+
public ActionResult Create()
|
290
272
|
|
291
273
|
{
|
292
274
|
|
275
|
+
string id = User.Identity.GetUserId();
|
276
|
+
|
277
|
+
string name = User.Identity.GetUserName();
|
278
|
+
|
279
|
+
//ViewBag.ResOwnerId = new SelectList(db.AspNetUsers, "Id", "UserName");
|
280
|
+
|
293
|
-
|
281
|
+
ViewBag.ResOwnerId = new SelectList(id);
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
ViewBag.ResId = new SelectList(db.Responses, "Id", "Title");
|
286
|
+
|
287
|
+
ViewBag.TopicId = new SelectList(db.Topics, "Id", "Title");
|
288
|
+
|
289
|
+
return View();
|
294
290
|
|
295
291
|
}
|
296
292
|
|
297
|
-
|
298
|
-
|
299
|
-
public int Id { get; set; }
|
300
|
-
|
301
|
-
public Nullable<int> SortNo { get; set; }
|
302
|
-
|
303
|
-
public Nullable<int> TopicId { get; set; }
|
304
|
-
|
305
|
-
public Nullable<int> ResId { get; set; }
|
306
|
-
|
307
|
-
[Display(Name = "タイトル")]
|
308
|
-
|
309
|
-
public string Title { get; set; }
|
310
|
-
|
311
|
-
[Display(Name = "レス内容")]
|
312
|
-
|
313
|
-
public string Contents { get; set; }
|
314
|
-
|
315
|
-
[Display(Name = "レスの書き込み者")]
|
316
|
-
|
317
|
-
public string ResOwnerId { get; set; }
|
318
|
-
|
319
|
-
public Nullable<int> ResponseCount { get; set; }
|
320
|
-
|
321
|
-
public Nullable<int> ViewCount { get; set; }
|
322
|
-
|
323
|
-
public Nullable<System.DateTime> RecentResDate { get; set; }
|
324
|
-
|
325
|
-
public Nullable<int> CountNice { get; set; }
|
326
|
-
|
327
|
-
public Nullable<int> CountLaugh { get; set; }
|
328
|
-
|
329
|
-
public Nullable<int> CountTears { get; set; }
|
330
|
-
|
331
|
-
public Nullable<int> CountSurprise { get; set; }
|
332
|
-
|
333
|
-
public Nullable<int> CountAnger { get; set; }
|
334
|
-
|
335
|
-
public Nullable<bool> HiddenFlag { get; set; }
|
336
|
-
|
337
|
-
public Nullable<bool> DeleteFlag { get; set; }
|
338
|
-
|
339
|
-
public Nullable<int> DeleteUserId { get; set; }
|
340
|
-
|
341
|
-
public Nullable<bool> DeleteUserIsAdmin { get; set; }
|
342
|
-
|
343
|
-
public Nullable<System.DateTime> DeleteDate { get; set; }
|
344
|
-
|
345
|
-
public Nullable<System.DateTime> CreateDate { get; set; }
|
346
|
-
|
347
|
-
public Nullable<int> CreateUserId { get; set; }
|
348
|
-
|
349
|
-
public Nullable<bool> CreateUserIsAdmin { get; set; }
|
350
|
-
|
351
|
-
public Nullable<System.DateTime> UpdateDate { get; set; }
|
352
|
-
|
353
|
-
public Nullable<int> UpdateUserId { get; set; }
|
354
|
-
|
355
|
-
public Nullable<bool> UpdateUserIsAdmin { get; set; }
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
public virtual AspNetUsers AspNetUsers { get; set; }
|
360
|
-
|
361
|
-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
362
|
-
|
363
|
-
public virtual ICollection<Responses> Responses1 { get; set; }
|
364
|
-
|
365
|
-
public virtual Responses Responses2 { get; set; }
|
366
|
-
|
367
|
-
public virtual Topics Topics { get; set; }
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
293
|
```
|
372
294
|
|
373
|
-
### 試したこと
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
(1)
|
378
|
-
|
379
|
-
Controllerを次のように書き換えたところ、次の画像のようにViewで表示されるDropDownListの中身がChar型になってしまいます。
|
380
|
-
|
381
|
-
return contentを用いてidとnameを表示した時にはハッシュ値のパスとユーザー名が表示できたのでidとnameには問題がないのではと考えています
|
382
|
-
|
383
|
-
(idとnameにIdentityの情報を格納し、Viewbag.ResOwnerId の値をコメントアウトしている行からその次の行のように書き換えました)
|
384
|
-
|
385
|
-
```c#
|
386
|
-
|
387
|
-
// GET: Responses/Create
|
388
|
-
|
389
|
-
public ActionResult Create()
|
390
|
-
|
391
|
-
{
|
392
|
-
|
393
|
-
string id = User.Identity.GetUserId();
|
394
|
-
|
395
|
-
string name = User.Identity.GetUserName();
|
396
|
-
|
397
|
-
//ViewBag.ResOwnerId = new SelectList(db.AspNetUsers, "Id", "UserName");
|
398
|
-
|
399
|
-
ViewBag.ResOwnerId = new SelectList(id);
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
ViewBag.ResId = new SelectList(db.Responses, "Id", "Title");
|
404
|
-
|
405
|
-
ViewBag.TopicId = new SelectList(db.Topics, "Id", "Title");
|
406
|
-
|
407
|
-
return View();
|
408
|
-
|
409
|
-
}
|
410
|
-
|
411
|
-
```
|
412
|
-
|
413
|
-
![イメージ説明](fbb2f9bc571cad065158c136b3651273.png)
|
414
|
-
|
415
|
-
表示されているchar型でのDropDownListの正体は、 ASP.NET Identityで用意したASPNetUsersテーブルのId値です
|
416
|
-
|
417
|
-
![イメージ説明](a107a72b2f6d6053ec3f52c9a07c52e3.png)
|
418
|
-
|
419
295
|
|
420
296
|
|
421
297
|
|
2
質問が長すぎたので短く修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,8 +18,6 @@
|
|
18
18
|
|
19
19
|
その後、ASP.NET identityを用いて実装したログイン機能を基に、トピックの中のレスの作成をしているのですが、行き詰まったので質問を投稿しました。
|
20
20
|
|
21
|
-
似たような投稿であると思い、3回に分けずに1回でまとめて投稿しましたが、どれかに回答をいただけるだけでもとてもありがたいです。長文ですがよろしくお願いします。
|
22
|
-
|
23
21
|
|
24
22
|
|
25
23
|
|
@@ -28,19 +26,15 @@
|
|
28
26
|
|
29
27
|
|
30
28
|
|
31
|
-
次の画像はトピックの中のレスを新規に作成するためのページなのですが、以下の
|
29
|
+
次の画像はトピックの中のレスを新規に作成するためのページなのですが、以下の問題を抱えています。
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
|
36
|
-
|
37
|
-
|
31
|
+
|
38
|
-
|
32
|
+
|
39
|
-
(
|
33
|
+
(1) レスの記入者を現在ログインしているユーザー名で固定したいが、ユーザー名をすべて表示してしまう。また、世の中の目標制作物に類似するものはそもそも「記入者=ログインユーザー名」だというのが自明なので表示してないように思えるので表示しない方法もあればご教授いただけたら幸いです。
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
|
35
|
+
|
36
|
+
|
43
|
-
![イメージ説明](f08ad8c48bf0d5e34d24cc7bcba0a097.png)!
|
37
|
+
![イメージ説明](f08ad8c48bf0d5e34d24cc7bcba0a097.png)!
|
44
38
|
|
45
39
|
|
46
40
|
|
@@ -378,88 +372,44 @@
|
|
378
372
|
|
379
373
|
### 試したこと
|
380
374
|
|
375
|
+
|
376
|
+
|
381
377
|
(1)
|
382
378
|
|
379
|
+
Controllerを次のように書き換えたところ、次の画像のようにViewで表示されるDropDownListの中身がChar型になってしまいます。
|
380
|
+
|
381
|
+
return contentを用いてidとnameを表示した時にはハッシュ値のパスとユーザー名が表示できたのでidとnameには問題がないのではと考えています
|
382
|
+
|
383
|
-
|
383
|
+
(idとnameにIdentityの情報を格納し、Viewbag.ResOwnerId の値をコメントアウトしている行からその次の行のように書き換えました)
|
384
|
-
|
385
|
-
|
384
|
+
|
386
|
-
|
387
|
-
以下はトピック一覧からレスを覗くために記したコードです。
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
```
|
385
|
+
```c#
|
386
|
+
|
392
|
-
|
387
|
+
// GET: Responses/Create
|
388
|
+
|
389
|
+
public ActionResult Create()
|
390
|
+
|
391
|
+
{
|
392
|
+
|
393
|
+
string id = User.Identity.GetUserId();
|
394
|
+
|
395
|
+
string name = User.Identity.GetUserName();
|
396
|
+
|
393
|
-
|
397
|
+
//ViewBag.ResOwnerId = new SelectList(db.AspNetUsers, "Id", "UserName");
|
398
|
+
|
399
|
+
ViewBag.ResOwnerId = new SelectList(id);
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
ViewBag.ResId = new SelectList(db.Responses, "Id", "Title");
|
404
|
+
|
405
|
+
ViewBag.TopicId = new SelectList(db.Topics, "Id", "Title");
|
406
|
+
|
407
|
+
return View();
|
408
|
+
|
409
|
+
}
|
394
410
|
|
395
411
|
```
|
396
412
|
|
397
|
-
上のコードの部分を実行しクリックする事で遷移後のページのURLは
|
398
|
-
|
399
|
-
http://localhost:51822/Responses/Index/1
|
400
|
-
|
401
|
-
となり、 urlの末尾に現在のレス一覧が所属するidがつくようになりました。
|
402
|
-
|
403
|
-
しかし、レス一覧のページ(URLの末尾にidが含まれている)において、次のコードを実行してクリックしても
|
404
|
-
|
405
|
-
http://localhost:51822/Responses/Create
|
406
|
-
|
407
|
-
という UrlになるためそもそもIdが引き継げないです。
|
408
|
-
|
409
|
-
```c#
|
410
|
-
|
411
|
-
<p>
|
412
|
-
|
413
|
-
@Html.ActionLink("Create New", "Create", new { id = UrlParameter.Optional })
|
414
|
-
|
415
|
-
</p>
|
416
|
-
|
417
|
-
```
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
(2)
|
422
|
-
|
423
|
-
調べたのですが、今回のようなModelからデータを引っ張る場合に空白値を加えるものについての記事は見つけられませんでした。
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
(3)
|
428
|
-
|
429
|
-
Controllerを次のように書き換えたところ、次の画像のようにViewで表示されるDropDownListの中身がChar型になってしまいます。
|
430
|
-
|
431
|
-
return contentを用いてidとnameを表示した時にはハッシュ値のパスとユーザー名が表示できたのでidとnameには問題がないのではと考えています
|
432
|
-
|
433
|
-
(idとnameにIdentityの情報を格納し、Viewbag.ResOwnerId の値をコメントアウトしている行からその次の行のように書き換えました)
|
434
|
-
|
435
|
-
```c#
|
436
|
-
|
437
|
-
// GET: Responses/Create
|
438
|
-
|
439
|
-
public ActionResult Create()
|
440
|
-
|
441
|
-
{
|
442
|
-
|
443
|
-
string id = User.Identity.GetUserId();
|
444
|
-
|
445
|
-
string name = User.Identity.GetUserName();
|
446
|
-
|
447
|
-
//ViewBag.ResOwnerId = new SelectList(db.AspNetUsers, "Id", "UserName");
|
448
|
-
|
449
|
-
ViewBag.ResOwnerId = new SelectList(id);
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
ViewBag.ResId = new SelectList(db.Responses, "Id", "Title");
|
454
|
-
|
455
|
-
ViewBag.TopicId = new SelectList(db.Topics, "Id", "Title");
|
456
|
-
|
457
|
-
return View();
|
458
|
-
|
459
|
-
}
|
460
|
-
|
461
|
-
```
|
462
|
-
|
463
413
|
![イメージ説明](fbb2f9bc571cad065158c136b3651273.png)
|
464
414
|
|
465
415
|
表示されているchar型でのDropDownListの正体は、 ASP.NET Identityで用意したASPNetUsersテーブルのId値です
|
1
説明の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
|
19
19
|
その後、ASP.NET identityを用いて実装したログイン機能を基に、トピックの中のレスの作成をしているのですが、行き詰まったので質問を投稿しました。
|
20
20
|
|
21
|
+
似たような投稿であると思い、3回に分けずに1回でまとめて投稿しましたが、どれかに回答をいただけるだけでもとてもありがたいです。長文ですがよろしくお願いします。
|
22
|
+
|
21
23
|
|
22
24
|
|
23
25
|
|
@@ -426,7 +428,9 @@
|
|
426
428
|
|
427
429
|
Controllerを次のように書き換えたところ、次の画像のようにViewで表示されるDropDownListの中身がChar型になってしまいます。
|
428
430
|
|
431
|
+
return contentを用いてidとnameを表示した時にはハッシュ値のパスとユーザー名が表示できたのでidとnameには問題がないのではと考えています
|
432
|
+
|
429
|
-
(Viewbag.ResOwnerId の値をコメントアウトしている行からその次の行のように書き換えました)
|
433
|
+
(idとnameにIdentityの情報を格納し、Viewbag.ResOwnerId の値をコメントアウトしている行からその次の行のように書き換えました)
|
430
434
|
|
431
435
|
```c#
|
432
436
|
|