bootstrap-select的选中值如何传至后台Controller,实现数据提交??

lxgmag2016 2018-07-28 05:08:29
我使用VS2015开发,采用H5+bootstrap3.3.7+MVC5+EF6+SQL SERVER2012环境开发;
我网上找了好多贴,此问题一直搞不定。

请高手指点一下。
...全文
1089 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
//客户选择事件触发方法;
function customerSelect(obj) {
var value = obj.options[obj.selectedIndex].value;
$.ajax({
url:"home/GetValue?select="+value,//这里就是Controller地址传值就是select=xxx,注意我的标点符号
type:"get",
............
success:function(){

},error:function(){

}
});

}
  • 打赏
  • 举报
回复
ajax提交,设置model有什么用,或者post提交
lxgmag2016 2018-07-28
  • 打赏
  • 举报
回复
lxgmag2016 2018-07-28
  • 打赏
  • 举报
回复
//客户选择事件触发方法;
function customerSelect(obj) {
var value = obj.options[obj.selectedIndex].value;
@Model.Customer_ID =value;
//ViewBag.ContractModel.Customer = obj.options[obj.selectedIndex].text;
}
lxgmag2016 2018-07-28
  • 打赏
  • 举报
回复
@Html.LabelFor(item => item.Customer, new { @class = "control-label col-lg-2" })
<div class="col-lg-2">

<select id="customerList" class="selectpicker show-tick form-control" data-live-search="true" data-size="5" onchange="customerSelect(this)">
@if (listCustomer != null && listCustomer.Any())
{
#region 1.构建下拉框选项;
StringBuilder sb = new StringBuilder();
string atArea = "";
bool firstItem = true;
//逐行添加显示的客户选项;
foreach (var m in listCustomer)
{
if (atArea != m.AtArea)
{
if (sb.ToString() != "")
{
sb.Append("</optgroup>"); //本组选项结束;
}
sb.AppendFormat("<optgroup data-subtext=\"{0}\">", m.AtArea); //label=\"{0}\" m.ID,
atArea = m.AtArea; //赋予新的组号;
}
//判断是否为首选项;
if (firstItem)
{
//本项默认选中;
sb.AppendFormat("<option id=\"{0}\" value=\"{0}\" selected>{1}</option>", m.ID, m.Name);
firstItem = false; //其它项默认为不选中;
}
else //否则此项默认不选中;
{
sb.AppendFormat("<option id=\"{0}\" value=\"{0}\">{1}</option>", m.ID, m.Name);
}
}
//添加本组结束;
sb.Append("</optgroup>");
@(new MvcHtmlString(sb.ToString()))
#endregion
}
</select>
</div>

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧