重装父视图我想实现如下陈述的情景:关闭从使用jQuery子视图对话框而不在MVC3
我使用MVC 3 Razor视图。
点击文本框(称为结果文本框),从主页视图(这是一个不同的视图,添加视图)打开一个对话框,并带回发到主控制器的动作。
在对话框(即添加视图)上,只需输入两个数字进行添加,并在其提交后,执行添加视图控制器操作的回传。
现在,当添加控制器操作处理完成后,我想要添加数字并关闭当前对话框(添加视图)并更新父视图(主视图)上的结果文本框,并添加结果。
注意:关闭对话框后,我不希望父视图重新加载或刷新。
现在,当我面临的问题是如何
1)取隐藏字段的值(容器除了值),并设置父页面上的结果测试盒?
2)从对话框本身关闭对话框(添加视图)?无需刷新父视图?
代码:
<h2> Input numbers to add</h2>
@using (Html.BeginForm("About","Home",FormMethod.Post, new {id = "dialogchildform"}))
{
@Html.Hidden("hdnresult", ViewData["result"], new { id = "hdnres" })
<div style="position: relative; margin-left: 200px; top: 80px">
<fieldset>
@Html.ValidationSummary(true)
<div class="editor-label">
Value 1
</div>
<div class="editor-field">
@Html.EditorFor(model => model.num1, new { id = "num1" })
@Html.ValidationMessageFor(model => model.num1)
</div>
<div class="editor-label">
Value 2
</div>
<div class="editor-field">
@Html.EditorFor(model => model.num2, new { id = "num2" })
@Html.ValidationMessageFor(model => model.num2)
</div>
</fieldset>
<p>
<input type="submit" value="Add and Retrun" id="inputSubmit" />
</p>
</div>
}
<script type="text/javascript">
$(document).ready(function() {
$("#inputSubmit").click(function() {
document.forms('dialogchildform').submit();
// txtParentResult is a Textbox on prent view to be updated
document.getElementById('txtParentResult').value
= document.forms('dialogchildform').hdnres.value;
// not updating the parent textbox
// $(window.document).dialog('close');
//gives error - Microsoft JScript runtime error: Object doesn't support property or method 'dialog'
//$("#mydiag").dialog("close");
// also gives error
//jQuery(".ui-dialog-content").dialog("close");
// again gives error - Microsoft JScript runtime error: Object doesn't support property or method 'dialog'
});
});
</script>
控制器动作:
[HttpPost]
public ActionResult Add(AddNum vAddNum)
{
objAddNum = vAddNum;
int result = objAddNum.AddNumbers();
ViewData["_ActionCloseDialog"] = "true";
ViewData["result"] = result;
return View();
}
Acheived this .. –