【发布时间】:2018-07-02 20:16:34
【问题描述】:
首先,如果文本框中没有值,我想隐藏模式。其次,data-dismiss 不起作用。我在代码中没有看到任何问题。有什么猜测吗?请给我建议。
/My form
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
@Html.TextBoxFor(m => m.txtName)
@Html.HiddenFor(m => m.hiddenNameId)
@Html.ValidationMessageFor(m => m.txtName, "", new { @class = "error" })
<button type="submit" id="submit" data-toggle="modal" data-target="#myModal">Produce Page</button>
}
//My Modal
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal" aria-hidden="true">
...
<div class="modal-header">
...
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
//Script
$(function () {
$('#submit').click(function () {
var value = $('#txtName').val();
if (value) {
$("#myModal").modal('show');
}
else {
$("#myModal").modal('hide');
}
});
});
【问题讨论】:
-
你是否包含了 jquery?这些方法需要 jQuery 才能工作。 (以及
bootstrap[.min].js)getbootstrap.com/docs/3.3/javascript
标签: jquery asp.net-mvc twitter-bootstrap