Build objects with a variable number of members?

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

The values ​​parameter is an object containing all pending values. Example

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

      

It's all well and good if none of these parameters are null or empty string. When this happens, System.Uri.EscapeDataString (String stringToEscape) throws an ArgumentNullException.
The problem is, at compile time, I don't know which parameters will be null. Also, I would rather not create an object for every possible combination of notnull values.
In my example, there are only three parameters, but what if there were 10? The possible combinations grow exponentially. Since it is not possible to add fields to type anon, I cannot add parameters one by one.

How can I solve this problem?

0


source to share


1 answer


You can force non-zero values ​​...



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

      

+2


source







All Articles