EditFor字符串列表 [英] EditFor for List of string
本文介绍了EditFor字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是从用户输入要5字符串(问题可能的答案),所以我有我的问题视图模型这些元素:
I want from user to input 5 strings (possible answers for question), so I have these elements in my question view model:
private IEnumerable<string> _possibleAnswers;
public IEnumerable<string> PossibleAnswers
{
get
{
return _possibleAnswers ?? new List<string>();
}
set
{
_possibleAnswers = value;
}
}
我的部分观点如下:
My partial view looks like this:
@model IEnumerable<string>
@{
ViewBag.Title = "PossibleAnswers";
}
@foreach (var str in Model)
{
@Html.EditorFor(m => str, new { @class = "form-control", placeholder = "Odgovor" })
}
但由于PossibleAnswers列表是空的,没有任何的编辑字段显示当我运行应用程序。我需要做什么来改变显示5编辑框和后他们回到正确到控制器?
But since PossibleAnswers list is empty, none of the edit fields show when I run the application. What do I need to change to display 5 edit fields and post them back correctly to controller?
推荐答案
返回_possibleAnswers?新列表{,,,,};
是的解决方案。
return _possibleAnswers ?? new List{"", "", "", "", ""}; is solution.
这篇关于EditFor字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文