Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there, I'm running a visual studio ASP.NET Core web application project and I'm trying to use the listBox to let users select multiple elements. The problem is that when I run my application instead of a listbox I get something like this. Activity: Run Walk Hike instead of a proper listbox

my cshtml
  Activity: 
        <asp:listbox id="activites" name="activities" runat="server" selectionmode="Multiple" row="1" set="" autopostback="true">
                <asp:listitem>Run
                <asp:listitem>Walk
                <asp:listitem>Hike

Update: even when i take an example of the asp.net attribute website it doenst work

cshtml
<pre> <asp:ListBox id="ListBox1" 
           Rows="6"
           Width="100px"
           SelectionMode="Single" 
           runat="server">

         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>

      </asp:ListBox>
:


output:

Item 1 Item 2 Item 3 Item 4 Item 5 Item 6

What I have tried:

I have tried a few differant things and I have the @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers in my code
Posted
Updated 9-Jun-23 2:51am
v2

If your output is
Item 1 Item 2 Item 3 Item 4 Item 5 Item 6

Then you need to apply CSS Styling.
 
Share this answer
 
If what you posted is exactly what you have in your cshtml, you don't have any closing tags on these elements. You have opening tags, but no closing tags.
CSHTML
<asp:ListBox id="activites" name="activities" runat="server" selectionmode="Multiple" row="1" set="" autopostback="true">
    <asp:ListItem>Run</asp:ListItem>
    <asp:ListItem>Walk</asp:ListItem>
    <asp:ListItem>Hike</asp:ListItem>
</asp:ListBox>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900