Asp.net mvc 使用Ajax.ActionLink更新整个页面
是否可以使用Ajax.ActionLink(…,…)来刷新整个页面,而不是使用UpdatetargetID 我更喜欢使用Ajax.ActionLink,因为经典的Html.ActionLink不是POST方法 我尝试:Asp.net mvc 使用Ajax.ActionLink更新整个页面,asp.net-mvc,visual-studio,Asp.net Mvc,Visual Studio,是否可以使用Ajax.ActionLink(…,…)来刷新整个页面,而不是使用UpdatetargetID 我更喜欢使用Ajax.ActionLink,因为经典的Html.ActionLink不是POST方法 我尝试: @Ajax.ActionLink("Click me", "MyAction", "MyController", new { value = '1234' }, new AjaxOptions { HttpMethod = "POST", Confirm = "Are you s
@Ajax.ActionLink("Click me", "MyAction", "MyController", new { value = '1234' }, new AjaxOptions { HttpMethod = "POST", Confirm = "Are you sure ?" }, null)
但是页面没有刷新,我不得不按F5
谢谢。在Jquery中进行ajax调用怎么样?像这样的
<button onclick="SomeFunction()" type="button" >Click me</button>
我希望我没有误解你的问题(我意识到这并不完全是使用ajax.actionlink)
问候
编辑
或者可能是一个牵强的想法,告诉updatetargetid的链接将你的整个页面包装在其中。大概是这样的:
function SomeFunction()
{
var url = '/MyController/MyAction/';
$.ajax({
type: "POST",
url: url,
data: { value: '1234' }, //if there are any parameters
dataType: "html", //or some other type
success: function (data) {
window.location.reload(true);
// or something in that area, maybe with the 'data'
},
error: function () {
//some derp
}
});
@Ajax.ActionLink("Click me", "MyAction", "MyController", new { value = '1234' }, new AjaxOptions { HttpMethod = "POST", Confirm = "Are you sure ?", UpdateTargetId = "TheDivToUpdate" }, null)
@Ajax.ActionLink("Click me", "MyAction", "MyController", new { value = '1234' }, new AjaxOptions { HttpMethod = "POST", OnSuccess="window.location.reload()" })
然后使用此div标记包装页面内容:
<div id="TheDivToUpdate">
//The content of your page
</div>
//页面的内容
我知道,这不是最漂亮的解决方案,但也许它对您有用?您实际上可以结合gardarvalur提出的两种方法来获得类似MVC的代码,而不需要将整个页面包装在div.Move window.location.reload()中,调用AjaxOptions对象的OnSuccess属性,如下所示:
function SomeFunction()
{
var url = '/MyController/MyAction/';
$.ajax({
type: "POST",
url: url,
data: { value: '1234' }, //if there are any parameters
dataType: "html", //or some other type
success: function (data) {
window.location.reload(true);
// or something in that area, maybe with the 'data'
},
error: function () {
//some derp
}
});
@Ajax.ActionLink("Click me", "MyAction", "MyController", new { value = '1234' }, new AjaxOptions { HttpMethod = "POST", Confirm = "Are you sure ?", UpdateTargetId = "TheDivToUpdate" }, null)
@Ajax.ActionLink("Click me", "MyAction", "MyController", new { value = '1234' }, new AjaxOptions { HttpMethod = "POST", OnSuccess="window.location.reload()" })
不涉及jQuery,只是MVC Ajax ActionLink中的一些简单的旧javascript。谢谢你的建议,但这次我不想使用jQuery。我更喜欢一个更像“MVC”的解决方案。aaa好的,我编辑了我的答案,以防万一,如果那样可以改为:)使用重新加载,我会得到下面的消息框“再次显示网页,web浏览器需要重新发送您以前的信息”只是好奇,GET方法有什么问题?使用GET方法来执行任务,例如更改应用程序中事物的状态(删除记录、更改状态等),这不是一个好主意。这里我需要一个actionLink来更改状态,这就是为什么我不想使用执行GET的经典html.actionLink。必须使用window.location.href=window.location.href;为了避免重发警告