如何在.cshtml中实现ComboBox ASP.NET

How to realise ComboBox in .cshtml ASP.NET

不工作asp:DropDownList . . . . . . . . . . . . ... . …… .

。 .. .. View result

Add.cshtml 使用布局 = "_Layout.cshtml"

 @section Head{
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="~/css/make-ad.css" rel="stylesheet" />
        <title>Document</title>
    
    <form asp-controller="Item" asp-action="Add" method="post">
        <label> Category</label>
        <input asp-for="CategoryId" type="text" />
    
        <asp:DropDownList class="ddlstyle"ID="DropDownList1" runat="server" >  
            <asp:ListItem Value="">Please Select</asp:ListItem>  
            <asp:ListItem>New Delhi </asp:ListItem>  
            <asp:ListItem>Greater Noida</asp:ListItem>  
            <asp:ListItem>NewYork</asp:ListItem>  
            <asp:ListItem>Paris</asp:ListItem>  
            <asp:ListItem>London</asp:ListItem>  
        </asp:DropDownList>  
        <button type="submit">
            Add
        </button>
    </form>

而不是 Web 表单 asp.net 试试这个 html5 ddl

<select  id="DropDownList1">
  <option value="">Please Select</option>
  <option value="Greater Noida">Greater Noida</option>
  <option value="NewYork">NewYork</option>
  <option value="Paris">Paris</option>
</select>