Javascript MVC视图:在引导下拉列表中获取值
我需要根据某人在下拉列表中选择的选项在视图数据中添加一个值:Javascript MVC视图:在引导下拉列表中获取值,javascript,html,asp.net-mvc,twitter-bootstrap,drop-down-menu,Javascript,Html,Asp.net Mvc,Twitter Bootstrap,Drop Down Menu,我需要根据某人在下拉列表中选择的选项在视图数据中添加一个值: <th class="centerAlign" style="font-weight: normal"> <div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" dat
<th class="centerAlign" style="font-weight: normal">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" *@ aria-expanded="true" style="height:28px">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li class="dropdown-header">Sort by</li>
<li role="separator" class="divider"></li>
<li><a href="#">Selected</a></li>
<li><a href="#">Unselected</a></li>
</ul>
</div>
</th>
编辑
控制器:
public ActionResult Index(int? page = null,
string brand_name = null,
string category_name = null,
string language_name = null,
string bco_name = null,
int? material_number = null,
bool? derivation_bool = null,
bool? artwork_bool = null,
bool? delivery_bool = null,
bool? export = null)
{
ViewData["brand_name"] = brand_name;
ViewData["category_name"] = category_name;
ViewData["language_name"] = language_name;
ViewData["bco_name"] = bco_name;
ViewData["material_number"] = material_number;
ViewData["derivation_bool"] = derivation_bool;
ViewData["artwork_bool"] = artwork_bool;
ViewData["delivery_bool"] = delivery_bool;
ViewData["export"] = export;
// if no page was specified in the querystring, default to the first page (1)
var pageNumber = page.HasValue ? page.Value : 1;
//ViewBag.OnePageOfProducts = onePageOfProducts;
// will only contain 12 products max because of the pageSize
var query = db.EContent_MaterialsFinalViewWithBcos
.Select(i => new Material
{
Brand = i.Brand,
Category = i.Category,
Language = i.Language,
Bco = i.Bco,
MaterialCod = i.MaterialCod,
Derivation = i.Derivation,
Artwork = i.Artwork,
BcoDelivery = i.BcoDelivery,
MaterialId = i.MaterialId
});
if (!string.IsNullOrWhiteSpace(brand_name))
query = query.Where(p => p.Brand.ToLower().Contains(brand_name.ToLower()));
if (!string.IsNullOrWhiteSpace(category_name))
query = query.Where(p => p.Category.ToLower().Contains(category_name.ToLower()));
if (!string.IsNullOrWhiteSpace(language_name))
query = query.Where(p => p.Language.ToLower().Contains(language_name.ToLower()));
if (!string.IsNullOrWhiteSpace(bco_name))
{
if (bco_name.ToLower().Contains("no"))
query = query.Where(p => p.Bco == null);
else
query = query.Where(p => p.Bco.ToLower().Contains(bco_name.ToLower()));
}
if(material_number != null)
query = query.Where(p => p.MaterialCod == material_number);
IPagedList<Material> onePageOfProducts = query
.OrderBy(i => i.MaterialCod)
.ToPagedList<Material>(pageNumber, defaultPageSize);;
return View("Index", onePageOfProducts);
}
public ActionResult索引(int?page=null,
字符串brand_name=null,
字符串类别\u name=null,
字符串语言_name=null,
字符串bco_name=null,
int?物料编号=空,
bool?派生值_bool=null,
bool?artwork_bool=null,
bool?交付\u bool=null,
bool?导出=空)
{
ViewData[“品牌名称”]=品牌名称;
ViewData[“类别名称”]=类别名称;
ViewData[“语言名称”]=语言名称;
ViewData[“bco_名称”]=bco_名称;
ViewData[“物料编号”]=物料编号;
ViewData[“派生布尔”]=派生布尔;
ViewData[“artwork_bool”]=artwork_bool;
ViewData[“交货期”]=交货期;
ViewData[“导出”]=导出;
//如果查询字符串中未指定页面,则默认为第一页(1)
var pageNumber=page.HasValue?page.Value:1;
//ViewBag.OnePageOfProducts=产品的一页;
//由于页面大小,最多只能包含12个产品
var query=db.EContent\u MaterialsFinalViewWithBcos
.选择(i=>新材料
{
品牌=i.品牌,
类别=i.类别,
语言,
Bco=i.Bco,
MaterialCod=i.MaterialCod,
推导=i.推导,
Artwork=i.Artwork,
b交付=i.b交付,
物质主义
});
如果(!string.IsNullOrWhiteSpace(品牌名称))
query=query.Where(p=>p.Brand.ToLower().Contains(Brand_name.ToLower());
如果(!string.IsNullOrWhiteSpace(类别名称))
query=query.Where(p=>p.Category.ToLower().Contains(Category_name.ToLower());
如果(!string.IsNullOrWhiteSpace(语言名称))
query=query.Where(p=>p.Language.ToLower().Contains(Language_name.ToLower());
如果(!string.IsNullOrWhiteSpace(bco_名称))
{
如果(bco_name.ToLower().包含(“否”))
query=query.Where(p=>p.Bco==null);
其他的
query=query.Where(p=>p.Bco.ToLower().Contains(Bco_name.ToLower());
}
if(物料编号!=空)
query=query.Where(p=>p.MaterialCod==物料编号);
IPagedList onePageOfProducts=查询
.OrderBy(i=>i.MaterialCod)
.ToPagedList(页码,默认页面大小);;
返回视图(“索引”,产品的一页);
}
视图:
使用PagedList.Mvc
@IPagedList模型
@使用(Html.BeginForm(“Index”,“Materials”,FormMethod.Get))
{
搜寻
@ActionLink(“重置过滤器”、“索引”,
无效的
新建{@class=“btn btn success custom pull left”、@style=“color:white”、@role=“button”}
)
输出到Excel
@{Html.RenderPartial(“_ajaxmeteriallist”,Model);}
}
局部视图:
<div class="panel panel-primary filterable" style="padding: 0px;
margin: 0px">
<div class="panel-heading" style="height:32px">
<h3 class="panel-title" style="font-size:14px">GDS eContent Master Data Service Tool</h3>
</div>
<table class="table table-bordered table-hover" style="width:100%">
<thead>
<tr>
<th>//all the headers</th>
</tr>
<tr>
<th class="centerAlign" style="font-weight: normal">
<input class="span2" type="text" name="brand_name"
value="@ViewData["brand_name"]" style="height:28px" placeholder="Search Brand for..."/></th>
<th class="centerAlign" style="font-weight: normal">
<input class="span2" type="text" name="category_name"
value="@ViewData["category_name"]" style="height:28px" placeholder="Search Category for..." />
</th>
//some headers like the upper input
<th class="centerAlign" style="font-weight: normal">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" *@ aria-expanded="true" style="height:28px">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li class="dropdown-header">Sort by</li>
<li role="separator" class="divider"></li>
<li><a href="#">Derived</a></li>
<li><a href="#">Not derived</a></li>
</ul>
</div>
</th>
//a bounch of dropdowns like the upper one
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<!--Labels are what the checkboxes are going to be searched for-->
<!--To do: Use switch instead of if statements-->
<tr>
<td class="centerAlign">@item.Brand.ToString()</td>
<td class="centerAlign">@item.Category.ToString()</td>
<td class="centerAlign">@item.Language.ToString()</td>
<td class="centerAlign">
@if (item.Bco == null)
{
<text>No Bco</text>}
else
{
<text>@item.Bco.ToString()</text> }
</td>
<td class="centerAlign">
@Html.ActionLink(@item.MaterialCod.ToString(),
"Details", "EContent_EcontentFields", new { id = item.MaterialId }, null)
</td>
<td class="centerAlign">
@if (item.Derivation != null && (bool)item.Derivation)
{
<input type="checkbox" checked="checked" value="true" disabled /><label class="hidden">TrueYes</label>
}
else
{
<input type="checkbox" value="false" disabled /><label class="hidden">FalseNo</label>
}
</td>
<td class="centerAlign">
@if (item.Artwork != null && (bool)item.Artwork)
{
<input type="checkbox" checked="checked" value="true" disabled /><label class="hidden">TrueYes</label>
}
else
{
<input type="checkbox" value="false" disabled /><label class="hidden">FalseNo</label>
}
</td>
<td class="centerAlign">
@if (item.BcoDelivery != null && (bool)item.BcoDelivery)
{
<input type="checkbox" checked="checked" value="true" disabled /><label class="hidden">TrueYes</label>
}
else
{
<input type="checkbox" value="false" disabled /><label class="hidden">FalseNo</label>
}
</td>
<td class="centerAlign">
<!-- To do: make this checkbox work -->
<input type="checkbox" value="@ViewData["export"]" />
</td>
</tr>
}
</tbody>
</table>
</div>
<div class="centerAlign" style="padding: 0px; margin: -8px">
<!-- output a paging control that lets the user navigation to the previous page, next page, etc -->
@Html.PagedListPager(Model, page => Url.Action("Index", "Materials", new
{
brand_name = Request["brand_name"],
category_name = Request["category_name"],
language_name = Request["language_name"],
bco_name = Request["bco_name"],
material_number = Request["material_number"],
page
}))
</div>
GDS eContent主数据服务工具
//所有标题
//一些标题类似于上面的输入
- 排序依据
//像上一个一样的下拉列表反弹
@foreach(模型中的var项目)
{
@item.Brand.ToString()
@item.Category.ToString()
@item.Language.ToString()
@如果(item.Bco==null)
{
无Bco}
其他的
{
@item.Bco.ToString()}
@ActionLink(@item.materialCode.ToString(),
“详细信息”,“EContent_EcontFields”,新的{id=item.MaterialId},空)
@if(item.Derivation!=null&&(bool)item.Derivation)
{
特鲁耶斯
}
其他的
{
法尔斯诺
}
@如果(item.Artwork!=null&&(bool)item.Artwork)
{
特鲁耶斯
}
其他的
{
法尔斯诺
}
@如果(item.BcoDelivery!=null&&(bool)item.Bc
@using PagedList.Mvc <!--import this so we get our HTML Helper-->
@model IPagedList<eContentMVC.Models.Material>
<!-- import the included stylesheet for some (very basic) default styling -->
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@using (Html.BeginForm("Index", "Materials", FormMethod.Get))
{
<div>
<div class="btn-group">
<button class="btn btn-default pull-left" type="submit"><i class="glyphicon glyphicon-search"></i> Search</button>
</div>
<div class="divid"></div>
<div class="btn-group">
<div>
@Html.ActionLink("Reset filters", "Index",
null,
new { @class = "btn btn-success custom pull-left", @style = "color:white", @role = "button" }
)
</div>
</div>
<!-- does nothing yet -->
<button class="btn btn-default custom pull-right" type="button"><i class="glyphicon glyphicon-file"></i> Export to Excel</button>
</div>
<div id="grid-list">
@{ Html.RenderPartial("_AjaxMaterialList", Model); }
</div>
}
<div class="panel panel-primary filterable" style="padding: 0px;
margin: 0px">
<div class="panel-heading" style="height:32px">
<h3 class="panel-title" style="font-size:14px">GDS eContent Master Data Service Tool</h3>
</div>
<table class="table table-bordered table-hover" style="width:100%">
<thead>
<tr>
<th>//all the headers</th>
</tr>
<tr>
<th class="centerAlign" style="font-weight: normal">
<input class="span2" type="text" name="brand_name"
value="@ViewData["brand_name"]" style="height:28px" placeholder="Search Brand for..."/></th>
<th class="centerAlign" style="font-weight: normal">
<input class="span2" type="text" name="category_name"
value="@ViewData["category_name"]" style="height:28px" placeholder="Search Category for..." />
</th>
//some headers like the upper input
<th class="centerAlign" style="font-weight: normal">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" *@ aria-expanded="true" style="height:28px">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li class="dropdown-header">Sort by</li>
<li role="separator" class="divider"></li>
<li><a href="#">Derived</a></li>
<li><a href="#">Not derived</a></li>
</ul>
</div>
</th>
//a bounch of dropdowns like the upper one
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<!--Labels are what the checkboxes are going to be searched for-->
<!--To do: Use switch instead of if statements-->
<tr>
<td class="centerAlign">@item.Brand.ToString()</td>
<td class="centerAlign">@item.Category.ToString()</td>
<td class="centerAlign">@item.Language.ToString()</td>
<td class="centerAlign">
@if (item.Bco == null)
{
<text>No Bco</text>}
else
{
<text>@item.Bco.ToString()</text> }
</td>
<td class="centerAlign">
@Html.ActionLink(@item.MaterialCod.ToString(),
"Details", "EContent_EcontentFields", new { id = item.MaterialId }, null)
</td>
<td class="centerAlign">
@if (item.Derivation != null && (bool)item.Derivation)
{
<input type="checkbox" checked="checked" value="true" disabled /><label class="hidden">TrueYes</label>
}
else
{
<input type="checkbox" value="false" disabled /><label class="hidden">FalseNo</label>
}
</td>
<td class="centerAlign">
@if (item.Artwork != null && (bool)item.Artwork)
{
<input type="checkbox" checked="checked" value="true" disabled /><label class="hidden">TrueYes</label>
}
else
{
<input type="checkbox" value="false" disabled /><label class="hidden">FalseNo</label>
}
</td>
<td class="centerAlign">
@if (item.BcoDelivery != null && (bool)item.BcoDelivery)
{
<input type="checkbox" checked="checked" value="true" disabled /><label class="hidden">TrueYes</label>
}
else
{
<input type="checkbox" value="false" disabled /><label class="hidden">FalseNo</label>
}
</td>
<td class="centerAlign">
<!-- To do: make this checkbox work -->
<input type="checkbox" value="@ViewData["export"]" />
</td>
</tr>
}
</tbody>
</table>
</div>
<div class="centerAlign" style="padding: 0px; margin: -8px">
<!-- output a paging control that lets the user navigation to the previous page, next page, etc -->
@Html.PagedListPager(Model, page => Url.Action("Index", "Materials", new
{
brand_name = Request["brand_name"],
category_name = Request["category_name"],
language_name = Request["language_name"],
bco_name = Request["bco_name"],
material_number = Request["material_number"],
page
}))
</div>