我有一个模型问题
public class Question
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int QuestionID { get; set; }
public int SystemAnswer { get; set; }
public int StudentAnswer { get; set; }
}
在视图中我有
@foreach (string[] item in ViewBag.Questions1 as List<string[]>)
{
<tr>
<td>
@Html.EditorFor(model => model.StudentAnswer)
@Html.ValidationMessageFor(model => model.StudentAnswer)
</td>
</tr>
}
其中ViewBag.Questions1
是x个字符串的列表
控制器
public ActionResult theAnswer(Question question)
{
int blah = question.StudentAnswer;
ViewBag.test = blah.ToString();
return View();
}
控制器应将question.StudentAnswer
int值传递给另一个视图;但是,它只传递question.StudentAnswer
的第一个值。如何让它通过question.StudentAnswer
??
答案 0 :(得分:0)
看起来你想一次传递多个问题,所以你需要在你的视图中有多个问题,我看不到问题视图的控制器....
事实上,我将摆脱ViewBag业务并将其作为一个视图模型传递,这将使事情变得更简单