我有一個視圖'父'在我的應用程序,我使用@ Html.BeginForm &一個提交按鈕來保存父視圖的數據。我也有一個父視圖內的部分視圖,我試圖從部分視圖調用ajax方法(使用jQuery),但每次它將我重定向到父窗體的操作方法。按鈕點擊從部分視圖重定向到父行動方法
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>
每次我試圖從局部視圖調用/主頁/ Test2的重定向我到/ home/Test1的(父窗體的動作)