【发布时间】:2015-11-16 08:51:58
【问题描述】:
我在我的项目中使用 MVC 5,我有一个链接,当用户单击时,会弹出一个引导模式窗口供用户输入新记录,视图有一个显示现有记录的数据表,我已经能够处理这部分,现在我希望能够从模态弹出窗口插入用户输入并在数据表上显示记录,而无需用户刷新页面?
这是我的代码:
<form role="form" class="form-horizontal" method="POST">
<!-- start: BOOTSTRAP EXTENDED MODALS -->
<div id="responsive" class="modal fade" tabindex="-1" data-width="760" style="display: none;top:50px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title">Responsive</h4>
</div>
<div class="modal-body">
<div class="form-group">
@Html.LabelFor(model => model.Surname, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Surname, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Surname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Firstname, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Firstname, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Firstname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Othernames, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Othernames, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Othernames, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Email, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ContactNumber, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ContactNumber, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ContactNumber, "", new { @class = "text-danger" })
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-light-grey">
Close
</button>
<button type="button" class="btn btn-blue">
Save changes
</button>
</div>
</div>
</div>
<!-- ends: BOOTSTRAP EXTENDED MODALS -->
</form>
感谢您的帮助。
【问题讨论】:
-
如果您想更新页面中的数据而不刷新,那么您将不得不在 javascript 中使用 ajax 调用来提交/获取数据,然后更新页面。
-
任何链接到如何做到这一点?
标签: javascript asp.net-mvc twitter-bootstrap