在ASP.NET MVC 3.0中实现后退按钮功能 [英] Implement Back button functionality in asp.net mvc 3.0

查看:109
本文介绍了在ASP.NET MVC 3.0中实现后退按钮功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在每个页面上实现返回"按钮功能.系统已经具有NEXT按钮来访问下一个视图.我正在使用@using(Html.BeginRouteForm()具有目标动作和控制器设置,在其中使用我的NEXT按钮(< button type =''button''id =''NextButton''> NEXT</button>)已放置.所有视图均为强类型视图.
现在,为实现BACK按钮,我添加了BACK按钮,并在jQUERY中附加了要调用的上一个View的控制器动作方法.代码如下:

I need to implement BACK button feature on each of my pages. System is already having NEXT button to visit next view. I am using @using (Html.BeginRouteForm() with target action and controller set, inside which my NEXT button (<button type=''button'' id=''NextButton''>NEXT </button>) has been placed. All the views are strongly-typed views.
Now, for implementing BACK button, I added BACK button and in jQUERY I attached controller action method of the previous View to call. The code is like:

$("#BackButton").click(function () {
                $.post("/PreviousController/PreviousAction/");
            });



当单击后退"按钮时,先前的控制器和动作将被正确调用,但先前的视图将不被渲染.它仍然仅显示当前视图.

请对此提供一些建议.

谢谢.



When clicked on BACK button, the previous controller and action is getting invoked properly but the previous view is not getting rendered. It still shows the current view only.

Please provide some suggestions on this.

Thanks.

推荐答案

(" ).click(function(){
("#BackButton").click(function () {


.post(" ); });
.post("/PreviousController/PreviousAction/"); });



当单击后退"按钮时,先前的控制器和动作将被正确调用,但先前的视图将不被渲染.它仍然仅显示当前视图.

请对此提供一些建议.

谢谢.



When clicked on BACK button, the previous controller and action is getting invoked properly but the previous view is not getting rendered. It still shows the current view only.

Please provide some suggestions on this.

Thanks.


您要做的只是发布到控制器操作,您尚未定义成功处理程序来确定如何处理该调用的结果.

我认为/PreviousController/PreviousAction/计算出用户最后一次调用的是什么?

在这种情况下,为什么不只在渲染视图时将其作为模型的一部分呢?

All you''re doing is posting to a controller action, you haven''t defined a success handler to determine what to do with the results of that call.

I take it that /PreviousController/PreviousAction/ works out what the last action called by the user was?

In which case, why not just make that part of your model when rendering your views?

public class SomeModel
{
    public string LastAction {get; set;}
}







public ActionResult SomeAction()
{
    var model = new SomeModel();
    model.LastAction = GetPreviousAction(); // Make this a method in some class that always returns the controller / action
    return View(model);
}



然后,在视图中,您只需渲染链接\按钮



Then in your Views, you can just render out links \ buttons

@model MyProject.SomeModel
<div class="my-view">
   <a id="my-link" href="@Model.LastAction">Back</a>

   <input type="button" name="backButton" id="backButton" value="Back" onclick="window.location.href='@Model.LastAction'">
</input></div>



或者,如果您想坚持使用已有的内容,请让/PreviousController/PreviousAction/返回要导航到的controller \ action的JSON.然后,您的脚本可能看起来像




Or, if you want to stick with what you''ve got, have your /PreviousController/PreviousAction/ return some JSON of the controller\action to navigate to. Your script could then look like



这篇关于在ASP.NET MVC 3.0中实现后退按钮功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆