【发布时间】:2014-05-12 09:08:06
【问题描述】:
我创建了一个 MVC5 应用程序,并使用以下代码创建一个下拉列表。它有 2 个值,如女性和男性,默认值为男性。
我想在用户更改下拉值时打开一个带有文本字段的弹出窗口,我应该怎么做?
索引代码:
<td>
@Html.DropDownListFor(modelItem => item.Genere, item.Genere)
</td>
型号代码:
public IEnumerable<SelectListItem> Genere
{
get
{
return new[]
{
new SelectListItem {Value = "M", Text = "Male"},
new SelectListItem {Value = "F", Text = "Female"}
};
}
}
更新视图代码
@model IEnumerable<Admin.Models.Admin>
<script src='https://code.jquery.com/jquery-1.11.0.min.js'></script>
<script src='https://code.jquery.com/ui/1.9.2/jquery-ui.min.js'></script>
<script>
$(document).ready(function () {
var dialog = $('#dialog').dialog({
});
$('#SystemType').change(function () {
//if($(this).val()=='F')
dialog.dialog('open');
});
});
</script>
<h3>My APP</h3>
p>
@using (Html.BeginForm())
{
}
@*<br style="margin-bottom:240px;" />*@
@Html.ActionLink("Create", "Create",
null, htmlAttributes: new { @class = "mybtn" })
<p>
</p>
<style type="text/css">
a.mybtn {
background: #fa0088;
}
</style>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Geneder)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DropDownListFor(modelItem => item.Geneder, item.Geneder, new { id = "M" })
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
<script type="text/javascript">
$(document).ready(function () {
$('#M').change(function () {
if ($(this).val() === "F") {
dialog.dialog('open');
}
});
});
</script>
【问题讨论】:
标签: c# html asp.net asp.net-mvc asp.net-mvc-4