如何在下拉列表MVC视图中添加复选框

本文关键字:添加 复选框 视图 MVC 下拉列表 | 更新日期: 2023-09-27 18:25:40

嗨,我正试图在我的下拉列表中添加复选框。我在谷歌上搜索了一下,我在asp.net中得到了一个例子,就像我在MVC3中尝试做的那样。在我的表单编辑中,用户必须能够检查下拉列表中的值。例如,在下面的制造商列表中,它只是显示我必须提供的值,并带有与该值相关的复选框。

我的表格:

 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EmsAdmin.Models.User>" %>
 <%@ Import Namespace="EmsAdmin.Models" %>
 <script type="text/javascript">
  //<![CDATA[
    // Focus on the first input box for the site
    $(document).ready(function () {
      $('#UserId').focus();
    });
  //]]>
</script>
<%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %>
<% using (Html.BeginForm()) {%>
  <%= Html.AntiForgeryToken() %>
  <p>
    <%= Html.LabelFor(e=>e.Id,"Id:") %>
    <%: Model.Id %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.PersonId,"Person:") %>
    <%= Html.DropDownListFor(e => e.PersonId, (SelectList)ViewData["allPersons"], "Select a person", new { @style = "width: 255px;" })%>
    <%= Html.ValidationMessageFor(e=>e.Person,"") %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.Email,"Email:") %>
    <%= Html.TextBoxFor(e => e.Email, new { @style = "width:250px;" })%>
    <%= Html.ValidationMessageFor(e=>e.Email,"") %>
  </p>
    <%= Html.LabelFor(e=>e.Approve,"Aprrove User:") %>
    <%= Html.CheckBoxFor(e=> e.Approve,Model.Approve) %><span>&nbsp;Switch this on if you want to add regitrar </span>
    <%= Html.ValidationMessageFor(e=>e.Approve,"") %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.ManufacturerDescription,"Brand:") %>
    <%= Html.DropDownListFor(e => e.ManufacturerDescription, (SelectList)ViewData["allManufacturers"], "Select  Brands", new { @style = "width: 255px;" })%>
    <%= Html.ValidationMessageFor(e=>e.ManufacturerDescription,"") %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.CountryName,"Country:") %>
    <%= Html.DropDownListFor(e => e.CountryName, (SelectList)ViewData["allCountries"], "Select Countries", new { @style = "width: 255px;" })%>
    <%= Html.ValidationMessageFor(e=>e.CountryName,"") %>
  </p>
  <p>
    <%= Html.LabelFor(e=>e.Role,"Role:") %>
    <%= Html.DropDownListFor(e => e.Role, (SelectList)ViewData["allRoles"], "Select Roles", new { @style = "width: 255px;" })%>
    <%= Html.ValidationMessageFor(e=>e.Role,"") %>
  </p>
  <p>
    <input type="submit" value="Save" />
    <%= Html.ActionLink("Cancel","Details",new {id=Model.Id},new {@title="exit without saving"}) %>
  </p>
<% } %>

如何在下拉列表MVC视图中添加复选框

没有basehtml输入,如带复选框的下拉列表。您可以使用像DevExpress这样的侧部件控制库,也可以自己进行控制。

在这里查找覆盖基本标记的jquery插件。