views:

82

answers:

1

In my asp.net mvc page, I want to call a RedirectToAction(actionName, controllerName, values).

The values parameter is an object that contains all the nessecary values. Example

return RedirectToAction(redirectAction, redirectController,
          new{ personId = foundId,
               personEmail = foundEmail,
               personHeigh = foundHeight});

This is all well, if none of those parameters is null or an empty string. When that happens, System.Uri.EscapeDataString(String stringToEscape) throws a ArgumentNullException.
The problem is I don't know at compile time what parameters will be null. Also, I would prefer not to make an object for each possible combination of notnull values.
In my example there are only three params, but what if would have 10? The possible combinations grow exponentially. Since it is not possible to add fields to an anon type, I cannot add the parameters one by one either.

How can I solve this issue?

+2  A: 

You can force non-null values...

return RedirectToAction(redirectAction, redirectController,
      new{ personId = foundId,
           personEmail =foundEmail ?? string.Empty,
           personHeigh = foundHeight ?? string.Empty});
Kieron
Yes, that was what I initially did. This doesn't solve the problem though because the System.Uri.EscapeDataString(String stringToEscape) still throws. I can't fill in a dummy value either because the pars are actually used for something ..
borisCallens