asp.net-core-mvctag-helpers

asp.net vnext Tag helpers select option not working


Pl help me to sort out the following issue..

In the View,

  <select asp-for="Frequency" asp-items=@ViewBag.Freqs 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.


Solution

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

    <select asp-for="Frequency" asp-items=@ViewBag.Freqs class="form-control">
    </select>
    

    Instead of

    <select asp-for="Frequency" asp-items=@ViewBag.Freqs class="form-control" />
    

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