Home Passing list using asp-for in razor pages
Reply: 0

Passing list using asp-for in razor pages

Tekrus
1#
Tekrus Published in 2017-11-12 14:12:23Z

I'm trying to fill out a class using BindProperty, one of the properties is a list that I would like to fill in depending on whether the user has entered an amount of the given item in a form.

Is it in any way possible to pass the list using asp-for, or in some way access the list in the .cshtml file from the corrosponding .cshtml.cs file?

The list of items that the user can choose from is currently being generated like this:

@{
    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>
    }
}

I would like all of the items with an entered value (larger than 0) to be added to a list, which can then be passed on to the model when the form gets submitted.

The rest of the information is sent using:

        <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" />
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299728 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO