我遇到了问题,我不知道如何解决。
在PartialView
中的PartialView
中按 Enter 键后,为什么要进入Modal
?
我的代码是这样的:
PartialView
中加载Modal
:
<script>
$(".panel-body").on('click', '.btn-success', function () {
var modal = document.getElementById('AddModal');
$('.Addspan').load('/Users/Phases/PhaseAdd/');
modal.style.display = "block";
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
});
</script>
&#13;
<div id="AddModal" class="modal AddModal">
<div class="modal-dialog modal-lg">
<div class="well Addspan">
</div>
</div><!-- Add modal-dialog -->
</div>
&#13;
PartialView
中的Controller
:
public ActionResult PhaseAdd() { ViewBag.CompanyId = new SelectList(db.Companies,&#34; CompanyId&#34;,&#34; Name&#34;); 返回PartialView(); }
Partialview
代码:
@using Labkhand.Models
@model Labkhand.Models.Phase
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@{
//بدست آوردن نام شرکت
LabkhandModel db = new LabkhandModel();
string co = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name).Company.Name;
}
<h4>افزودن عنوان شغلی برای <strong class="text-danger">@co</strong></h4>
@Html.ValidationSummary(true, "", new {@class = "text-danger"})
<div class="row" id="EditPhasePanel">
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new {@class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new {htmlAttributes = new {@class = "form-control",
onkeypress = "return runScript(event)"}})
@Html.ValidationMessageFor(model => model.Name, "", new {@class = "text-danger"})
</div>
</div>
</div>
<div class="modal-footer">
<input type="button" value="ذخیره" class="btn btn-danger btn-outline btnAddPhase"/>
<button type="button" class="btn btn-primary closesPassModal" data-dismiss="modal" onclick="closeModal();">بستن</button>
</div>
</div>
//Close modal
<script type="text/javascript">
function closeModal() {
document.getElementById('AddModal').style.display = "none";
}
</script>
}
&#13;
Modal
图片:
按 Enter 键后:
答案 0 :(得分:0)
我解决了。
$(document).keypress(
function(event){
if (event.which == '13') {
event.preventDefault();
}
});