回答編集履歴
2
追記
test
CHANGED
@@ -481,3 +481,111 @@
|
|
481
481
|
}
|
482
482
|
|
483
483
|
```
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
**【追伸】**
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
下の 2018/12/06 12:12 の私のコメントで「こうしてみてはどうかという案を回答欄に追記しておきます」と書きましたが、それを以下に書いておきます。
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
コメントにも書きましたが、検証等はしておりませんので参考にとどめ、自力で必要な修正等を行ってコードを書いてください。
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
質問者さんの Controller のコードの中の、
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
```
|
504
|
+
|
505
|
+
// 選択ボックスのオプションを準備
|
506
|
+
|
507
|
+
ViewBag.ServerOptions = db.TSituation.Select(s => new SelectListItem
|
508
|
+
|
509
|
+
{
|
510
|
+
|
511
|
+
Text = s.situation,
|
512
|
+
|
513
|
+
Value = s.id.ToString()
|
514
|
+
|
515
|
+
});
|
516
|
+
|
517
|
+
```
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
を以下のように変更して、
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
```
|
526
|
+
|
527
|
+
List<TSituation> situations = db.TSituation.ToList();
|
528
|
+
|
529
|
+
Dictionary<int, SelectList> dictionary = new Dictionary<int, SelectList>();
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
foreach (TSituation item in situations)
|
534
|
+
|
535
|
+
{
|
536
|
+
|
537
|
+
dictionary.Add(item.ID, new SelectList(situations, "ID", "Situation", item.ID));
|
538
|
+
|
539
|
+
}
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
ViewBag.Situation = dictionary;
|
544
|
+
|
545
|
+
```
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
View を以下のようにしたらどうなりますか?
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
```
|
554
|
+
|
555
|
+
@model List<Kintai_CS_.Models.TKintai>
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
@{
|
560
|
+
|
561
|
+
/**/
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
ViewBag.Title = "Index";
|
566
|
+
|
567
|
+
Layout = "~/Views/Shared/_Layout.cshtml";
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
Dictionary<int, SelectList> dictionary = (Dictionary<int, SelectList>)ViewBag.Situation;
|
572
|
+
|
573
|
+
}
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
・・・略・・・
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
@Html.DropDownList("<name 属性に指定する名前>", dictionary[Model[idx].Situation])
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
・・・略・・・
|
586
|
+
|
587
|
+
```
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
(注)上のコードの <name 属性に指定する名前> は EditorFor を使った際にどのようになるか調べて、同じになるように設定してください
|
1
訂正
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
最初の回答の 2018/12/04 08:55 の私のコメントで「質問者さんのケース(複数行の一括更新・・・個人的にはかなり乱暴なような気もしますが)で SelectList を ViewBag 経由で View に渡すにはどうするかを考えてみました・・・」と書きましたが、それを以下に書いておきます。
|
6
6
|
|
7
7
|
|
8
8
|
|