Can I solve this? (?:)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Can I solve this? (?:)

    Hello,

    I have the following:

    return returnUrl == null ? RedirectToActio n("Index", "Home") : Redirect
    (returnUrl);

    I get an error:

    Type of conditional expression cannot be determined because there is
    no implicit conversion between 'System.Web.Mvc .RedirectToRout eResult'
    and 'System.Web.Mvc .RedirectResult '

    Is there a way to fix this without needing to use an IF?

    Thanks,

    Miguel
  • shapper

    #2
    Re: Can I solve this? (?:)

    On Nov 20, 6:26 pm, "Michael B. Trausch" <m...@trausch.u swrote:
    On Thu, 20 Nov 2008 09:46:12 -0800 (PST)
    >
    shapper <mdmo...@gmail. comwrote:
    I have the following:
    >
    return returnUrl == null ? RedirectToActio n("Index", "Home") :
    Redirect (returnUrl);
    >
    I get an error:
    >
    Type of conditional expression cannot be determined because there is
    no implicit conversion between 'System.Web.Mvc .RedirectToRout eResult'
    and 'System.Web.Mvc .RedirectResult '
    >
    Is there a way to fix this without needing to use an IF?
    >
    I'd use an 'if' statement here, for readability---if statements are
    easier to quickly parse with your head when compared to (most) usages
    of the ternary operator.  IMHO, the ternary operator should only be
    used with either a variable or a literal for the possible return
    values, and function calls should be done in if statements.
    >
    It looks as if you're in need of parenthesis.  Try:
    >
    return((returnU rl == null) ? RedirectToActio n("Index", "Home") :
      Redirect(return Url));
    >
    If you're still getting an error, then you probably need casts to
    something that makes sense within the context of your code.
    >
            --- Mike
    Thanks!

    Comment

    • =?ISO-8859-1?Q?G=F6ran_Andersson?=

      #3
      Re: Can I solve this? (?:)

      shapper wrote:
      Hello,
      >
      I have the following:
      >
      return returnUrl == null ? RedirectToActio n("Index", "Home") : Redirect
      (returnUrl);
      >
      I get an error:
      >
      Type of conditional expression cannot be determined because there is
      no implicit conversion between 'System.Web.Mvc .RedirectToRout eResult'
      and 'System.Web.Mvc .RedirectResult '
      >
      Is there a way to fix this without needing to use an IF?
      >
      Thanks,
      >
      Miguel
      Just cast one or both of the result operands to the data type of the
      return value.

      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      Comment

      Working...