繁体   English   中英

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

[英]How to add checkboxes in dropdown list MVC view

嗨,我想在我的下拉列表中添加复选框。 我用谷歌搜索它,我在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>
<% } %>

没有基本的 html输入,例如带有复选框的下拉列表。 您可以使用像DevExpress这样的侧面部分控制库,也可以自己控制。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM