模态弹出状态
Model Popup state
我正在使用 MVC 局部视图在 Jquery 模型弹出窗口中显示一个表单。在提交时,我调用我的操作方法来验证用户输入,如果验证失败,我需要再次填充模式弹出窗口。我面临的问题是,在提交时它调用子操作方法,我能够在我的部分视图中获得 ViewData.ModelState.IsValid 但是无法自动显示模式弹出窗口取决于 ModelState 值。我尝试了下面的 jquery 代码,但没有成功。
局部视图
@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>
}
儿童行动
[ChildActionOnly]
[HttpPost]
public ActionResult JobAlert(JobAlertModel JobAlert)
{
JobAlertModel ja = new JobAlertModel();
if (ModelState.IsValid)
{
ja.email = JobAlert.email;
return Redirect("/");
}
else
{
return PartialView("popup", ja);
}
}
我弄清楚了自己。以防有人想知道。
@if (!ViewData.ModelState.IsValid)
{
<script type="text/javascript">
$(document).ready(function () {
$("#modal-opener").click();
});
</script>
}
我正在使用 MVC 局部视图在 Jquery 模型弹出窗口中显示一个表单。在提交时,我调用我的操作方法来验证用户输入,如果验证失败,我需要再次填充模式弹出窗口。我面临的问题是,在提交时它调用子操作方法,我能够在我的部分视图中获得 ViewData.ModelState.IsValid 但是无法自动显示模式弹出窗口取决于 ModelState 值。我尝试了下面的 jquery 代码,但没有成功。
局部视图
@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>
}
儿童行动
[ChildActionOnly]
[HttpPost]
public ActionResult JobAlert(JobAlertModel JobAlert)
{
JobAlertModel ja = new JobAlertModel();
if (ModelState.IsValid)
{
ja.email = JobAlert.email;
return Redirect("/");
}
else
{
return PartialView("popup", ja);
}
}
我弄清楚了自己。以防有人想知道。
@if (!ViewData.ModelState.IsValid)
{
<script type="text/javascript">
$(document).ready(function () {
$("#modal-opener").click();
});
</script>
}