の をView
編集できる がList
ありViewModel
ます。コードは表示機能まで機能します。しかし、同じリストの値をビューから取得できません。
public ActionResult Funtion()
{
List<ViewModel> ViewModel= (List<ViewModel>)TempData["ViewModel"];
return View(ViewModel);
}
[HttpPost]
public ActionResult UserFormSubmission(List<ViewModel> ViewModel)
{
return View();
}
POST 関数のリストの値が null です。ビューからコントローラーに値を取得するにはどうすればよいですか。
編集:チェックボックスの状態を含む MVC で IEnumerable リストをコントローラーに渡す方法 に関する質問への解決策に記載されているソリューションを使用してみました。. しかし、次のエラーが発生しました。
タイプ 'System.Collections.Generic.IEnumerable の式に [] を使用したインデックス作成を適用することはできません
AntiForgeryToken
また、 、 などの特定のタグの使用法を理解できませんHiddenFor
でした。可能であれば、誰かが簡単な解決策またはより良い説明を考え出してください。
EDIT 2 :に変更@model IEnumerable<ViewModel>
し@model List<ViewModel>
、エラー Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.IEnumerable has been modified.
編集 3:
との値をコントローラーに取得できましたTextbox
がCheckBox
、RadioButton
[ DropDownList's selected values cant be identified at the
HttpPost]` 関数は? ここで何が欠けていますか?
@for (i = 0; i < Model.Count(); ++i)
{
if (Model[i].TypeId == 4)
{
//radiobutton
for (int j = 0; j < Model[i].Options.Count(); ++j)
{
<div>
@Html.HiddenFor(m => m[i].Options[j].OptionId)
@Html.HiddenFor(m => m[i].Options[j].OptionValue)
@Html.HiddenFor(m => m[i].Options[j].Id)
@Html.RadioButtonFor(m => m[i].Options[j].Value, @Model[i].Options[j].DisplayText)
@Html.DisplayFor(m => m[i].Options[j].DisplayText)
</div>
}
}
}