【发布时间】:2018-03-17 01:26:34
【问题描述】:
我有一个问题,我不知道如何解决它。
为什么我在Modal 中的PartialView 中按Enter 键后进入PartialView?
我的代码是这样的:
- 在
Modal中加载PartialView:
<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>
<div id="AddModal" class="modal AddModal">
<div class="modal-dialog modal-lg">
<div class="well Addspan">
</div>
</div><!-- Add modal-dialog -->
</div>
-
和
PartialView中的Controller:公共 ActionResult PhaseAdd() { ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name"); 返回部分视图(); }
-
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>
}
Modal图片:按下 Enter 键后:
【问题讨论】: