I have an ActionResult calling another ActionResult.
I have a call to an ActionResult in my case statement which doesn't work. Here is what I have:
public ActionResult GetReport(string pNum)
{
....
switch (methodId)
{
case 1:
case 5:
{
var actionResult = GetP1Report("33996",false) as ActionResult;
break;
}
}
return actionResult;
}
I get the following error: 'actionResult' does not exist in the current context
If I do the following it works but not quite what I need:
public ActionResult GetReport(string pNum)
{
....
var actionResult = GetP1Report("33996",false) as ActionResult;
switch (methodId)
{
case 1:
case 5:
{
// var actionResult = GetP1Report("33996",false) as ActionResult;
break;
}
}
return actionResult;
}
How do I get the actionResult to work in my case statement such that it is visible when I do
return actionResult
Just declare it first (with a default value, I guess), outside of the switch statement:
ActionResult actionResult = null;
switch (methodId)
{
case 1:
case 5: // PVT, PVT-WMT
{
actionResult = GetP1Report("33996",false) as ActionResult;
break;
}
}
return actionResult ?? new View();
Note: I added the ?? new View()
as a default value, in case none of the cases assign anything to actionResult
-- modify this as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With