我的 View 不是强类型 View ,我需要在 Controller 操作中循环访问请求参数以确定发布的值。
是否有更好的方法来遍历 nameValueCollection AllKeys?
我目前正在遍历请求参数并适本地设置值。
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
}
我看到这段代码中有相当多的重复。有更好的方法来处理这个问题吗?
最佳答案
也许是这样的?
queryObject.CustomerId = Request.Params["CustomerId"];
queryObject.OrderId = Request.Params["OrderId"];
关于c# - 迭代请求参数的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4505049/