我希望你能帮助我解决一个难题。在我在下面问我的问题之前,我要写一堆代码:)
在我的页面上单击某些内容时:
<input type='button' value='1' name='derp1' onclick='OpenTelerikWindow(1)' />
<br/>
<input type='button' value='2' name='derp2' onclick='OpenTelerikWindow(2)' />
我用 Jquery 打开 Telerik 窗口:
function OpenTelerikWindow(arg) {
var url = '/Controller/Derp/';
$.ajax({
type: "GET",
url: url,
dataType: "html",
data: { id: arg }
success: function (data) {
$('#PaymentWindow').data("tWindow").content(data);
$('#PaymentWindow').data("tWindow").center().open().refresh();
}
});
}
我的控制器 ActionResult:
public ActionResult Derp(int id)
{
SomeModel someModel = _GetModel(id);
return PartialView("Derp", someModel)
}
然后我的 Telerik Window 的内容是这样的:
@SomeModel
<div id="theDerpina">
<div>
//Some Stuff
@using (Ajax.BeginForm("Derpina1", "Controller", new { id = SomeModel.id }, new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "theDerpina",
InsertionMode = InsertionMode.Replace
}, new { id = "feedback-form" }))
{
//Some Stuff
<button type="submit" > Submit</button>
<br/>
<button type="button" > CloseWindow </button>
}
</div>
<div>
//More Stuff
@using (Ajax.BeginForm("Derpina2", "Controller", new { id = SomeModel.id }, new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "theDerpina",
InsertionMode = InsertionMode.Replace
}, new { id = "feedback-form" }))
{
//Different Stuff
<button type="submit" > Submit</button>
<br/>
<button type="button" > CloseWindow </button>
}
</div>
</div>
我的另外两个控制器动作:
public ActionResult Derpina1(int id)
{
SomeModel someModel = _GetModel(id);
if(ModelState.IsValid)
{
//DoStuff
return View("SomeOtherView");
}
else
{
return PartialView("Derp", someModel);
}
}
public ActionResult Derpina2(int id)
{
SomeModel someModel = _GetModel(id);
if(ModelState.IsValid)
{
//DoDifferentStuff
return View("SomeOtherView");
}
else
{
return PartialView("Derp", someModel);
}
}
当我打开一次窗口时,一切正常。但是,如果我要打开窗口,关闭它,然后再次打开它,就会发生奇怪的事情。例如,假设我单击了 Derpina1 的提交按钮,我将收到两个对该特定控制器操作的调用。如果我在 Firebug 中监控控制台,我会看到对控制器操作的两个单独调用。如果我再次关闭窗口,再次打开它,然后再次提交,同样的事情会发生,我的控制器操作现在将收到 4 次对我的控制器操作的调用。
也许你们可以指出正确的方向。我是否应该以不同的方式打开 Telerik 窗口,如果发生这种情况,我是否应该使用不同的方法返回 ModelError?(因为如果我收到 ModelError,我将面临同样的行为)