简体   繁体   English

从控制器内部渲染另一个控制器视图(非局部视图)

[英]Render Another Controllers View From Within a Controller (Not Partial View)

We are in the process of converting a Ruby on Rails 3.2 App to .NET MVC 4 using C# as the language. 我们正在使用C#作为语言将Ruby on Rails 3.2 App转换为.NET MVC 4的过程。 Is there a way to render a view from another controller within the current controller in C# similar to the way Rails does. 有没有一种方法可以从C#中的当前控制器中的另一个控制器渲染视图,就像Rails一样。

For example, in Rails, in your current controller you can call: 例如,在Rails中,在当前控制器中,您可以调用:

render :template => 'another_controller/action'

When searching online all I could find were articles/SO questions regarding rendering partial views from a C# controller. 在线搜索时,我能找到的所有关于从C#控制器渲染局部视图的文章/ SO问题。 Is rendering a full view from another controller considered not best practice? 从其他控制器渲染全视图不是最佳实践吗?

You need to call RedirectToAction 您需要致电RedirectToAction

Pass it the action name and the controller name, each as a string. 将每个动作名称和控制器名称作为字符串传递给它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM