Javascript 使用Ajax刷新ASP.NET MVC中的引导模式
我有一个引导模式。当我单击“提交”按钮时,页面会刷新并丢失该模式。我想在单击“提交”按钮后继续使用该模式,以显示成功消息或错误消息。我是MVC新手,无法理解 这是我的情态Javascript 使用Ajax刷新ASP.NET MVC中的引导模式,javascript,asp.net,ajax,twitter-bootstrap,Javascript,Asp.net,Ajax,Twitter Bootstrap,我有一个引导模式。当我单击“提交”按钮时,页面会刷新并丢失该模式。我想在单击“提交”按钮后继续使用该模式,以显示成功消息或错误消息。我是MVC新手,无法理解 这是我的情态 <div class="modal fade" id="signin_modal"> <div class="modal-dialog"> <div class="modal-content"> <div class=" modal-he
<div class="modal fade" id="signin_modal">
<div class="modal-dialog">
<div class="modal-content">
<div class=" modal-header">
Create An Account
</div>
<div class="modal-body">
@using (Html.BeginForm("Login", "Home", FormMethod.Post))
{
<table>
<tr><td>@Html.Label("username", null, new { style = " font-size:12px; font-weight:normal; font-family:consolas; " })</td></tr>
<tr><td>@Html.TextBox("name", null, new { style = " width:200px; height:30px; " })</td></tr>
<tr> </tr>
<tr><td>@Html.Label("password", null, new { style = " font-size:12px; font-weight:normal; font-family:consolas; " })</td></tr>
<tr><td>@Html.TextBox("password", null, new { style = " width:200px; height:30px " })</td></tr>
</table>
}
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Sign in</button>
@*<button type="reset" class="btn btn-warning">Reset</button>*@
<button type="reset" class="btn btn-default">Reset</button>
</div>
</div>
</div>
</div>
创建帐户
@使用(Html.BeginForm(“Login”、“Home”、FormMethod.Post))
{
@Label(“username”,null,新{style=“font size:12px;font-weight:normal;font-family:consolas;”)
@TextBox(“name”,null,新{style=“宽度:200px;高度:30px;”})
@Label(“password”,null,新{style=“font size:12px;font-weight:normal;font-family:consolas;”)
@TextBox(“密码”,空,新{style=“宽度:200px;高度:30px”})
}
登录
@*重置*@
重置
我知道这是一个老问题,但我会这样做
如果您使用的是强类型视图模型,则可以添加名为IsModalShown
的属性,即
public class Foo
{
public bool IsModalShown { get; set; }
}
将此渲染为视图中的隐藏对象,即
@Html.HiddenFor(m => m.IsModalShown)
当模态打开时,将隐藏值设置为true,这将使模态状态能够发回控制器操作,即
$('#signin_modal').on('show.bs.modal', function (e) {
$('#IsModalShown').val(true);
})
请注意,以上内容取决于您使用的引导版本,但官方网站上还有其他文档
然后将以下内容添加到视图中,视图会自动弹出
$(function(){
@if(Model.IsModalShown)
{
$('#signin_modal').modal('show');
}
});
弹出窗口中显示的其他字段也可以使用模型中的属性进行设置