Pattern to iterate Request Params

Posted by NOOBie on Stack Overflow See other posts from Stack Overflow or by NOOBie
Published on 2010-12-21T23:52:41Z Indexed on 2010/12/21 23:54 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

My view is not a strongly typed view and I need to iterate through Request Params in the controller action to determine the values posted.

Is there a better way to iterate through the nameValueCollection AllKeys?

I am currently looping through the Request Params and setting values appropriately.

 foreach (var key in Request.Params.AllKeys)
 { 
     if (key.Equals("CustomerId"))
        queryObject.CustomerId = Request.Params[key];
     else if (key.Equals("OrderId"))
       queryObject.OrderId= Request.Params[key];
     //and so on
 }

I see a considerable amount of repetition in this code. Is there a better way to handle this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET