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

Passing list using asp-for in razor pages

user1940 Published in May 21, 2018, 10:34 pm

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())
            <input type="hidden" value="@item.Name" />
            <td><input type="number" value="@item.Amount"/></td>

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 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">

<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.320066 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO