By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Can I solve this? (?:)

P: n/a
Hello,

I have the following:

return returnUrl == null ? RedirectToAction("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.RedirectToRouteResult'
and 'System.Web.Mvc.RedirectResult'

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

Thanks,

Miguel
Nov 20 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Nov 20, 6:26*pm, "Michael B. Trausch" <m...@trausch.uswrote:
On Thu, 20 Nov 2008 09:46:12 -0800 (PST)

shapper <mdmo...@gmail.comwrote:
I have the following:
return returnUrl == null ? RedirectToAction("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.RedirectToRouteResult'
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((returnUrl == null) ? RedirectToAction("Index", "Home") :
* Redirect(returnUrl));

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!
Nov 20 '08 #2

P: n/a
shapper wrote:
Hello,

I have the following:

return returnUrl == null ? RedirectToAction("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.RedirectToRouteResult'
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
_____
http://www.guffa.com
Nov 21 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.