在不同的控制器.NET MVC调用方法 [英] .NET MVC Call method on different controller

查看:135
本文介绍了在不同的控制器.NET MVC调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何从一个动作方法调用不同的控制器的方法?我不希望重定向。我想打电话给在不同的控制器返回一个字符串,用在我的操作方法应对的方法。

Can anybody tell me how to call a method on a different controller from within an action method? I don't want to redirect. I want to call a method on a different controller that returns a string and use the response within my action method.

推荐答案

声音在我耳边像你应该重构你的应用程序,并提取产生串出一个新的独立的类功能(或重用现有类,如果你有一个适合),并让两个控制器使用该类。

Sounds in my ears like you should refactor your application, and extract the functionality that generates the string out to a new seperate class (or reuse an existing class, if you have one that fits) and let both controllers use that class.

这篇关于在不同的控制器.NET MVC调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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