Asp.net mvc 从editorfor内部for循环获取值
我对ASP.NET有点陌生,所以我很难找到如何做到这一点。我有一个问题,用户会给出一个数量(比如说5),然后我必须创建5个文本框让用户输入一些数字。我的逻辑是,用户键入数字量,我为每个数字创建一个html.editor。问题是我需要每个编辑器的值 像这样Asp.net mvc 从editorfor内部for循环获取值,asp.net-mvc,razor,Asp.net Mvc,Razor,我对ASP.NET有点陌生,所以我很难找到如何做到这一点。我有一个问题,用户会给出一个数量(比如说5),然后我必须创建5个文本框让用户输入一些数字。我的逻辑是,用户键入数字量,我为每个数字创建一个html.editor。问题是我需要每个编辑器的值 像这样 <div> @for (int i = 0; i < Model.qtde; i++) { @Html.
<div>
@for (int i = 0; i < Model.qtde; i++)
{
@Html.EditorFor(c => c.numeros, new
{
htmlAttributes =
new
{
@class = "form-control input-lg",
autofocus = true,
@type = "number",
min = 0,
max = 1000
}
})
@Html.ValidationMessageFor(model => model.numeros, "",
new { @class = "text-danger" })
}
</div>
@对于(int i=0;ic.numeros,新
{
HTMLAT贡品=
刚出现的
{
@class=“表单控制输入lg”,
自动对焦=真,
@type=“number”,
最小值=0,
最大值=1000
}
})
@Html.ValidationMessageFor(model=>model.numeros,“,
新建{@class=“text danger”})
}
qtde:用户键入的数字金额
数字:用户键入的数字
如果需要更多信息,我将进行相应更新。使用以下代码将为您提供正确的值(numeros[I]将为您提供每个编辑器的值),并将numeros声明为列表或数组:
@for (int i = 0; i < Model.qtde; i++)
{
@Html.EditorFor(c => c.numeros[i], new
{
htmlAttributes =
new
{
@class = "form-control input-lg",
autofocus = true,
@type = "number",
min = 0,
max = 1000
}
})
@Html.ValidationMessageFor(model => model.numeros[i], "",
new { @class = "text-danger" })
}
for(int i=0;i