不更改地址栏的ASP.NET MVC重定向 [英] ASP.NET MVC Redirection without address bar changing

查看:73
本文介绍了不更改地址栏的ASP.NET MVC重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,只是一个简短的问题:
如何在不更改浏览器地址栏的情况下从一个控制器的操作重定向到另一个控制器的操作?

我现在使用RedirectToAction,但这会使浏览器显示新地址.我只想呈现其他控制器动作的内容.如果有关系,我也想将几个(字符串)值传递给另一个视图.

非常感谢

Hey friends, just a short question :
How can I redirect from one controller''s action to a different controller''s action without having the address bar of the browser changed?

I user RedirectToAction now, but this causes the browser to display the new address. I just want to render the content of a different controller''s action. If it matters, I want to pass a couple of (string) values to the other view as well.

Thanks a lot

推荐答案

那么,就HTTP重定向而言,这不是重定向,因此看到您的行为可能并不奇怪. ''正在寻找缺席.重定向的目的不是控制渲染,而是服务器将请求资源的临时(或永久)移动告知请求客户端.

而不是从控制器操作重定向,为什么不决定重定向"并将其存储在您的ViewBag中?您始终可以从视图中进行RenderAction(并传递这些字符串参数).

干杯.
This isn''t a redirect then, in terms of an HTTP redirect, so it''s may not be too surprising to see the behaviour you''re looking for is absent. The purpose of a redirect is not to control rendering, it''s for the server to tell the requesting client about a temporary (or permanent) move of a resource.

Rather than redirecting from the controller action, why not decide to "redirect" and store it in your ViewBag? You can always RenderAction from the view (and pass those string params).

Cheers.


我发现,您可以像这样从控制器渲染完全不同的视图:
I''ve found out that you can render a total different view from a controller like so :
return View("~/controller/action.aspx", viewModel);


就我而言,这满足了我渲染一个完全不同的视图的需求,并且能够使用模型将数据传递到该视图.

我曾经是一个非常非常初学者(n00b)的问题/解决方案,但是您知道,任何人都必须学习一些时间;)


In my case this satisfies my needs of rendering a total different view and having the ability to pass data to that view using a model.

My have been a very very very beginner (n00b) question/solution, but you know, anybody''s gotta learn some time ;)


这篇关于不更改地址栏的ASP.NET MVC重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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