如何从另一个类传递数据 [英] How to pass data from another class

查看:60
本文介绍了如何从另一个类传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我正在努力编写以下方法,因为我想将数据从值控制器传递到用户控制器。值控制器返回一个数据模型,我想寻求帮助/建议,如何将值模型数据传递给用户控制器。

Dear all,
I am struggling to code the following method, as I would like to pass data from the "Values controller" into the "user controller". The values controller returns a model of data, I would like to seek help/advice, how can pass the values model data into the user controller.

public class UserController : ApiController
    {
       [Authorize(Roles = "admin")]
        public void Get()
        {
               var result = new ValuesController();
               return result.Get();
              

        }




public class ValuesController : ApiController
{
// GET api/values

public IEnumerable<string> Get()
{

return new string[] { "value1", "value2" };
}





非常感谢。



Many thanks.

推荐答案

你可以在void方法中返回一个值!

You can't return a value in a void method!
public void Get()
{
       var result = new ValuesController();
       return result.Get();
}

您必须将其声明为返回IEnumerable< string>:

You would have to declare it as returning a IEnumerable<string>:

public IEnumerable<string> Get()
{
       var result = new ValuesController();
       return result.Get();
}


这篇关于如何从另一个类传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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