2017-02-10 3 views
0
@if (Model.CurrentPage.TagPage != null) 
        { 

         @Html.DropDownListFor(x => x.CurrentPage.TagPage, Model.CurrentPage.TagPage, new { @class = "FormTextbox__Input search-filter-field", @name = "search-blog-name-value" }) 
        } 
        else 
        { 
         <select id="CurrentPage_TagList" name="search-blog-name-value" class="FormTextbox__Input search-filter-field"> 
          <option value="*">No Tag Page found</option> 
         </select> 
        } 

Вынесено HTML является:Как я могу заполнить Checkbox с помощью HTML-помощника

<select class="FormTextbox__Input search-filter-field" id="CurrentPage_TagList" name="CurrentPage.TagPage"> 
    <option value="5G">5G</option> 
<option value="Connectivity">Connectivity</option> 
<option value="Digital transformation">Digital transformation</option> 
<option value="Radio system">Radio system</option> 
</select> 

Я хочу, чтобы флажок вместо этого раскрывающийся. Можете ли вы мне помочь? Ниже требуется Checkbox

<div data-action="checkbox-tray" class="hidden"> 
           <input type="checkbox" value="5G" />5G</br> 
           <input type="checkbox" value="Connectivity" />Connectivity</br> 
           <input type="checkbox" value="Digital transformation" />Digital transformation</br> 
           <input type="checkbox" value="Radio system" />Radio system</br> 
           <input type="checkbox" value="Mobile" />Mobile</br> 

          </div> 

ответ

0

Паван, потому что вы запрашиваете флажок вместо выпадающего списка, я покажу вам, как сделать это в качестве взаимоисключающих пользовательского ввода. Поскольку я делаю взаимоисключающим, вы должны использовать радиокнопки вместо флажков. Вы можете использовать флажки с jquery или написать метод расширения, чтобы сделать пользовательский контроль взаимоисключающим, но я покажу вам более простой способ.

Контроллер:

public class CurrentPage 
{ 
    public IList<SelectListItem> TagPage { get; set; } 
} 

public class MyStackOverflowModel 
{ 
    public CurrentPage CurrentPage = new CurrentPage(); 
} 

public class HomeController : Controller 
{ 
    [HttpPost] 
    public ActionResult Index3(MyStackOverflowModel myStackOverflowModel, string GetValue) 
    { 
     //GetValue contains selection 
     return View(myStackOverflowModel); 
    } 

    public ActionResult Index3() 
    { 
     List<SelectListItem> items = new List<SelectListItem>(); 
     items.Add(new SelectListItem { Text = "5G", Value = "5G" }); 
     items.Add(new SelectListItem { Text = "Connectivity", Value = "Connectivity" }); 
     items.Add(new SelectListItem { Text = "Digital transformation", Value = "Digital transformation", Selected = true }); 
     items.Add(new SelectListItem { Text = "Radio system", Value = "Radio system" }); 
     items.Add(new SelectListItem { Text = "Mobile", Value = "Mobile" }); 

     MyStackOverflowModel myStackOverflowModel = new MyStackOverflowModel(); 
     myStackOverflowModel.CurrentPage.TagPage = items; 
     //myStackOverflowModel.CurrentPage.TagPage = null; 

     return View(myStackOverflowModel); 
    } 

Вид:

@model WebApplication9.Controllers.MyStackOverflowModel 
@{ 
    Layout = null; 
} 

<!DOCTYPE html> 

<html> 
<head> 
    <meta name="viewport" content="width=device-width" /> 
    <title>Index3</title> 
</head> 
<body> 
    @using (Html.BeginForm()) 
    { 
     if (Model.CurrentPage.TagPage != null) 
     { 
      foreach (SelectListItem item in Model.CurrentPage.TagPage) 
      { 
       <div> 
        @Html.RadioButton("GetValue", item.Text) 
        @Html.Label(item.Text) 
       </div> 
      } 
     } 
     else 
     { 
      <select id="CurrentPage_TagList" name="search-blog-name-value" class="FormTextbox__Input search-filter-field"> 
       <option value="*"> No Tag Page found</option> 
      </select> 
     } 
     <input type="submit" value="Submit" /> 
    } 
</body> 
</html> 
Смежные вопросы