I want to use asp:CheckBoxList , but the browser gives an error:

Uncaught SyntaxError: Failed to execute 'matches' on 'Element': 'A ASP: CHECKBOXLIST' is not a valid selector.

 <form method="get" action=""> <h3>Критерії вибору:</h3> <p>Тип</p> <asp:CheckBoxList runat="server" ID="CheckboxList1" RepeatColumns="3"> <asp:ListItem Selected="true">Option 1</asp:ListItem> <asp:ListItem>Option 2</asp:ListItem> </asp:CheckBoxList> <p>Ціна</p> <label for="minPrice">Від:</label> <input type="number" name="minPrice" id="minPrice" value="@ViewBag.min"/> <label for="maxPrice">до:</label> <input type="number" name="maxPrice" id="maxPrice" value="@ViewBag.max"/> <input type="submit" value="Пошук"/> </form> 

Help solve the problem.

  • Give an example code. - edem
  • You are trying to use ASP.NET WebForms controls on an ASP.NET MVC view. These are different frameworks, they can not be mixed. - kmv
  • @kmv can be mixed, but not in this context. - SᴇM
  • one
    If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

You cannot use the controls from the asp.net webforms on the asp.net mvc presentation, You must either manually write html select/option or use Razor Syntax . Examples:

HTML Tag

 <select id="Cars" name="Cars"> <option value="0">Volvo</option> <option value="1">Saab</option> <option value="2">Mercedes</option> <option value="3">Audi</option> </select> 

Razor:

Controller:

 public ActionResult SelectCategory() { List<SelectListItem> items = new List<SelectListItem>(); items.Add(new SelectListItem { Text = "Volvo", Value = "0"}); items.Add(new SelectListItem { Text = "Saab", Value = "1" }); items.Add(new SelectListItem { Text = "Mercedes", Value = "2", Selected = true }); items.Add(new SelectListItem { Text = "Audi", Value = "3" }); ViewBag.Cars= items; return View(); } 

View:

 @Html.DropDownList("Cars")