Asp.net MVC - 返回"主机"使用部分意见时,控制器 [英] Asp.net MVC - Returning to "host" controller when using partial views

查看:173
本文介绍了Asp.net MVC - 返回"主机"使用部分意见时,控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为参数控制器,它允许一些常见到我的对象模型参数进行编辑/查看。使用一对夫妇的部分景观进行创建/观看 - ShowParameters.ascx和CreateParameters.ascx

I have a controller called Parameters which allows some parameters common to my object model to be edited/viewed. Creating/viewing is performed using a couple of partial views - ShowParameters.ascx and CreateParameters.ascx.

我有许多其他控制器,所有使用ShowParameters.ascx展示自己的相关参数。这工作正常。

I have a number of other controllers that all use ShowParameters.ascx to show their related Parameters. That works fine.

不过,我有我的CreateParameters.ascx局部视图的一个问题。它要求在我的控制器的参数创建参数命名CreateParameter一个动作。我的问题是,我想它返回到previous控制器和显示索引视图该控制器,以使用户可以看到该参数已创建

However, I have a problem with my CreateParameters.ascx partial view. It calls an action named CreateParameter in my Parameters controller to create the parameter. My problem is, I would like it to return to the previous controller and show the Index view for that controller, so that the user can see that the parameter has been created.

如何将我的控制器参数确定它应该回归到哪个控制器?

How can my Parameters controller determine which controller it should return to?

谢谢,

桶状

推荐答案

您可以通过一个额外的 RETURNURL 参数,您CreateParameter操作,因此会重定向到这个指定网址。而在你CreateParameters.ascx局部视图,你可以通过在构造链接当前的控制器名和行动。

You could pass an additional returnUrl parameter to your CreateParameter action so that it will redirect to this given url. And in your CreateParameters.ascx partial view you could pass the current controller name and action when you construct the link.

另一种选择是始终重定向到 Request.UrlReferrer 您CreateParameter行动中。

Another option would be to always redirect to the Request.UrlReferrer inside your CreateParameter action.

这篇关于Asp.net MVC - 返回"主机"使用部分意见时,控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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