在剃刀页面中使用asp-for传递列表

时间:2017-11-12 14:12:23

标签: asp.net-mvc asp.net-mvc-4 razor razor-2

我正在尝试使用BindProperty填写一个类,其中一个属性是我想要填写的列表,具体取决于用户是否在表单中输入了给定项目的数量。

是否可以使用asp-for传递列表,或以某种方式从相应的.cshtml.cs文件访问.cshtml文件中的列表?

目前正在生成用户可以选择的项目列表:

@{
    foreach (var item in DatabaseExtract.ExtractAllItems())
    {
        <tr>
            <td>@item.Name</td>
            <td>@item.Amount</td>
            <td>@item.Placement</td>
            <input type="hidden" value="@item.Name" />
            <td><input type="number" value="@item.Amount"/></td>
        </tr>
    }
}

我希望将所有输​​入值(大于0)的项目添加到列表中,然后在提交表单时将其传递给模型。

其余信息使用以下方式发送:

        <div class="row">
            <div class="col-sm-6 form-group">
                <label for="SubproductBlueprint">Path:</label>
                <input type="text" class="form-control" id="SubproductBlueprint" placeholder="Input path here" asp-for="CurrentSubproduct.BlueprintPath">
            </div>
            <div class="col-sm-6 form-group">
                <label for="SubproductPlacement">Placement:</label>
                <input type="text" class="form-control" id="SubproductPlacement" placeholder="Input placement here" asp-for="CurrentSubproduct.Placement">
            </div>
        </div>

<input type="submit" value="Add item" class="btn btn-primary btn-lg btn-space" asp-page-handler="AddSubproduct" />

0 个答案:

没有答案