私のビューモデルクラスは
public class StudentQuestions
{
public int StudentId{ get; set; }
public int FormId { get; set; }
public virtual ICollection<Questions> Question { get; set; }
}
質問クラスは
public partial class Questions
{
public int questionID { get; set; }
public string field_name { get; set; }
public string question { get; set; }
public int qutyp_refID {get,set}
public string description { get; set; }
public int ord { get; set; }
public bool IsEnabled { get; set;}
public virtual ICollection<Answers> Answers { get; set; }
} 私からしてみれば
@model Test.ViewModels.StudentQuestions
<table>
<tr><td>@Model.FormId</td><td>@Model.StudentId</td></tr>
@foreach(var q in Model.Question)
{
<tr>
<td> @Html.CheckBoxForFor(i=> i.Question.question)</td>
</tr>
}
</table>
i.Question.question にアクセスできませんが、次のように CheckBox、TextBox でアクセスできます。Textbox を TextBoxFor に、CheckBox を CheckBoxFor に、TextBox を TextBoxFor に変更したい
@foreach(var q in Model.Question)
{
<tr>
@if (@q.qutyp_refID == 4)
{
<td>@Html.CheckBox(q.questionID.ToString())
</td>
}
else if (@q.qutyp_refID <= 2)
{
<td>@Html.TextBox("txtDateQuestions", DateTime.Today.ToString("dd/MM/yyyy"), new { style = "width: 120px" }) </td>
}
else
{
<td>@Html.TextBox(q.questionID.ToString(), null)</td>
}
</tr>
}
前もって感謝します.........