jquery Asp.net 中选择的插件 MVC 4 未显示在视图中
jquery Chosen plugin in Asp.net MVC 4 does not show in the view
正在尝试为 MultiSelectList 使用选定的插件,但即使在我的视图中显示该插件,我也遇到了问题。各位大侠能看出来是什么原因吗?
查看:
@model test.Models.Employee
....
<script src="~/Scripts/chosen.jquery.min.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link href="~/Content/chosen.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$('.chzn-select').chosen();
});
</script>
@using (Html.BeginForm())
{
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
@Html.LabelFor(model => model.Services)
@Html.ListBoxFor(model => model.Services, ViewBag.serviceList as MultiSelectList,
new { @class = "chzn-select", id="service", data_placeholder = "Choose Services..." })
@Html.ValidationMessageFor(model => model.Services)
<input type="submit" value="Create" class="btn btn-default" />
}
<script>
$(".chzn-select").chosen();
</script>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
如果我想在用户提交表单时从服务字段正确绑定数据,并将其保存到 MYSQL table,我是否需要为 [=14= 修复我的模型]到public IEnumerable>string> Services { get; set; }
?
当我使用 IEnumerable
并迁移它时,我没有看到 Services
的列,这让我担心保存服务数据。
型号:
public class Employee
{
[Key]
public string EmpId { get; set; }
public string Name { get; set; }
public string Services { get; set; }
}
我自己想出来了。检查我的网络选项卡,发现有些文件没有加载。您需要将一些代码替换为适当的部分,如下所示。
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script src="@Url.Content("~/Scripts/chosen.jquery.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/chosen.min.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$('.chzn-select').chosen();
});
</script>
}
正在尝试为 MultiSelectList 使用选定的插件,但即使在我的视图中显示该插件,我也遇到了问题。各位大侠能看出来是什么原因吗?
查看:
@model test.Models.Employee
....
<script src="~/Scripts/chosen.jquery.min.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link href="~/Content/chosen.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$('.chzn-select').chosen();
});
</script>
@using (Html.BeginForm())
{
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
@Html.LabelFor(model => model.Services)
@Html.ListBoxFor(model => model.Services, ViewBag.serviceList as MultiSelectList,
new { @class = "chzn-select", id="service", data_placeholder = "Choose Services..." })
@Html.ValidationMessageFor(model => model.Services)
<input type="submit" value="Create" class="btn btn-default" />
}
<script>
$(".chzn-select").chosen();
</script>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
如果我想在用户提交表单时从服务字段正确绑定数据,并将其保存到 MYSQL table,我是否需要为 [=14= 修复我的模型]到public IEnumerable>string> Services { get; set; }
?
当我使用 IEnumerable
并迁移它时,我没有看到 Services
的列,这让我担心保存服务数据。
型号:
public class Employee
{
[Key]
public string EmpId { get; set; }
public string Name { get; set; }
public string Services { get; set; }
}
我自己想出来了。检查我的网络选项卡,发现有些文件没有加载。您需要将一些代码替换为适当的部分,如下所示。
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script src="@Url.Content("~/Scripts/chosen.jquery.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/chosen.min.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$('.chzn-select').chosen();
});
</script>
}