本文介绍了Partail视图中的Call to Action方法不工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有一个View''Parent'',我正在使用@ Html.BeginForm&用于保存父视图数据的提交按钮。我在Parent视图中也有一个局部视图,我试图从局部视图调用ajax方法(使用jQuery),但每次它将我重定向到父窗体的动作方法。
I have a View ''Parent'' in my application , I am using @Html.BeginForm & a submit button to save data of Parent view . I also have one partial view inside Parent view , I am trying to call ajax method(using jQuery) from partial view but each time it redirects me to action method of parent form.
Parent View
@using (Html.BeginForm("Test1", "Home", new { id = 1 }, FormMethod.Get))
{
@Html.Partial("TestPartial", Model)
<div>
<input id="Button1" type="submit" value="Parent" />
</div>
}
Partial View
<script>
function onClientClick() {
$.ajax({
url: "/Home/Test2",
type: "GET",
dataType: "json",
contentType: ''application/json; charset=utf-8'',
data: JSON.stringify({ ID: 1 }),
cache: false,
success: function (data) {
alert(''Success'');
},
error: function (err, result) {
alert("Error" + err.responseText);
}
});
}
</script>
<div>
<input type="submit" name="submit" onclick="onClientClick()" value="Submit" />
</div>
谢谢。
Thanks.
推荐答案
谢谢。
Thanks.
@using (Html.BeginForm("Test1", "Home", new { id = 1 }, FormMethod.Get))
{
@Html.Partial("TestPartial", Model)
<div>
<input id="Button1" type="button" value="Parent" />
</div>
}
partial
<div>
<input type="submit" name="submit" onclick="onClientClick()" value="Submit" />
</div>
2.摆脱表格行动
2. Get rid of form action
@using (Html.BeginForm(null, null, new { id = 1 }, FormMethod.Get))
{
@Html.Partial("TestPartial", Model)
<div>
<input id="Button1" type="submit" value="Parent" />
</div>
}
partial the same
这篇关于Partail视图中的Call to Action方法不工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!