1

How to make an dropdown list in form-group with method="post"? The list has to be dynamic, and the parameter send has to be something else from what is shown in label. I was trying something like this:

    <div class="form-group">
        <label asp-for="Product.Category">Choose category:</label>
        <select class="form-control" id="Product.Category">
@foreach (var category in Model.Categories)
{
            <option>category.CategoryName</option>
}
        </select>
    </div>

But it doesn't work for me, and I have to send to controller the category Id not category name.

The goal is that:

User selects category from dropdown list, and the Id of category is being send to controller.

1
  • because I dont know how, thats why I ask for a solution Commented Mar 8, 2018 at 12:12

1 Answer 1

1
<option value="@category.Id">@category.CategoryName</option>
Sign up to request clarification or add additional context in comments.

1 Comment

the value is always null, could you help me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.