Javascript 模型弹出状态
我正在使用MVC局部视图在Jquery模型弹出窗口中显示一个表单。在提交时,我调用我的操作方法来验证用户输入,如果验证失败,我需要再次填充模式弹出窗口。我面临的问题是,在提交时,它调用子操作方法,我能够在部分视图中获取ViewData.ModelState.IsValid,但是无法自动显示模式弹出窗口取决于ModelState值。我尝试使用jquery代码,但没有成功 局部视图Javascript 模型弹出状态,javascript,jquery,asp.net-mvc,model-view-controller,umbraco7,Javascript,Jquery,Asp.net Mvc,Model View Controller,Umbraco7,我正在使用MVC局部视图在Jquery模型弹出窗口中显示一个表单。在提交时,我调用我的操作方法来验证用户输入,如果验证失败,我需要再次填充模式弹出窗口。我面临的问题是,在提交时,它调用子操作方法,我能够在部分视图中获取ViewData.ModelState.IsValid,但是无法自动显示模式弹出窗口取决于ModelState值。我尝试使用jquery代码,但没有成功 局部视图 @inherits Umbraco.Web.Mvc.UmbracoViewPage<WebApplication
@inherits Umbraco.Web.Mvc.UmbracoViewPage<WebApplicationDemo1.Models.JobAlertModel>
<script>
$(function () {
$("#dialog-modal").dialog({
autoOpen: false,
width: 600,
height: 550,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "dissolve",
duration: 1000
}
});
$("#modal-opener").click(function () {
$("#dialog-modal").dialog("open");
});
});
</script>
<button id="modal-opener">Job Alerts</button>
<div id="dialog-modal" title="Basic modal dialog">
@using (Html.BeginForm())
{
<fieldset>
<legend>Product</legend>
<div class="editor-label">
@Html.LabelFor(m => m.email )
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.email)
@Html.ValidationMessageFor(model => model.email)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.location)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.location)
@Html.ValidationMessageFor(model => model.location)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.password)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.password)
@Html.ValidationMessageFor(model => model.password)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.search)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.search)
@Html.ValidationMessageFor(model => model.search)
</div>
<input type="submit" value="Create new job alert" />
</fieldset>
}
</div>
@if (!ViewData.ModelState.IsValid)
{
<div>There are some errors</div>
<script type="text/javascript">
$("#modal-opener").click();
</script>
}
我明白了。万一有人想知道
@if (!ViewData.ModelState.IsValid)
{
<script type="text/javascript">
$(document).ready(function () {
$("#modal-opener").click();
});
</script>
}
@if(!ViewData.ModelState.IsValid)
{
$(文档).ready(函数(){
$(“#模式开启器”)。单击();
});
}
@if (!ViewData.ModelState.IsValid)
{
<script type="text/javascript">
$(document).ready(function () {
$("#modal-opener").click();
});
</script>
}