asp.net vnext Tag helpers select option not working

5k views Asked by At

Pl help me to sort out the following issue..

In the View,

  <select asp-for="Frequency" [email protected] class="form-control" />

and in Controller,

SelectListItem[] items = {  new SelectListItem() { Text = "item 1", Value= "Nrk" },
                            new SelectListItem() { Text = "item 2", Value= "Nrk 2" }
                            };

        ViewBag.Freqs = items;
        return View();

But I am not getting the list in the drop down box.

2

There are 2 answers

0
Karthick On BEST ANSWER

After two days, I found the problem.. the following is worked

<select asp-for="Frequency" [email protected] class="form-control">
</select>

Instead of

<select asp-for="Frequency" [email protected] class="form-control" />

@Matt DeKrey, thanks for pointing the tag issue... I will edit my post as u mentioned.

1
Steve Woods On

I had this problem where my items weren't loading into the select list.

Basically the scaffolding is incorrectly done as:

<select asp-for="PropertyId" asp-items="ViewBag.PropertyItems" />

When in fact it should fully generate the HTML tag instead:

<select asp-for="PropertyId" asp-items="ViewBag.PropertyItems"></select>

Had me scratching my head for ages until I noticed that the Create form was working, but was different to the Edit form for the same model.

Annoying - but simple :)