1
Follows code:
Controller:
public ActionResult teste1(int num1, int num2)
{
// Aqui quero obter os valores da variável model1 e model2 da classe MyClass
var result = MyClass.Teste2(num1 , num2);
}
Model:
public class MyClass
{
public static Teste2(int num1, int num2)
{
var model1 = new AspNetUser();
var model2 = new AspNetUser1();
using (var ctx = new Entities())
{
model1 = ctx.Table.Where( x => ...).FirstOrDefault();
model2 = ctx.Table.Where( x => ...).FirstOrDefault();
}
//aqui: como retornar com "model1" e "model2" para ação "ActionResult" onde tem variável "result"?
}
}
How can I return with variables model1
and model2
for variable result
? Because the AspNetUser
and AspNetUser
tbm are classes created with ADO.NET Entity Data Model. I have tried making a ToArray
or ToList
and I couldn’t. I’m having trouble returning.
Can someone help me ?
These codes do not make much sense. It would be better if you put a real example that has doubt. If you only want to know how to return more than one value there is already an answer to this in https://answall.com/q/195460/101 and therefore it is duplicate. Or https://answall.com/q/94882/101 if you are not using C# 7. The exact solution depends on what you need.
– Maniero
Another example that may not be exactly the same more can be useful https://answall.com/a/80993/30045
– Brunno
The comment didn’t help much, but it seems to confirm what I already thought. I just can’t say if it’s a better solution because you don’t have enough information to make that decision. Or use tuples or a class as Brunno indicated.
– Maniero