我使用
有时我需要传递一个空的参数值,例如:
我可以手动创建URL,但我想使用helper方法。
有什么建议吗?
Html.ActionLink(string linkText, string actionName, object routeValues)
重载来向Action方法传递一些参数。有时我需要传递一个空的参数值,例如:
?item1=&item2=value
我在创建的匿名类型中指定参数,并将其作为routeValues
传递,但是null
和string.Empty
都会导致URL省略空的item1
参数。new { item1 = null, item2 = "value" }
new { item1 = string.Empty, item2 = "value" }
new { item1 = "", item2 = "value" }
// all result in:
?item2=value
我可以手动创建URL,但我想使用helper方法。
有什么建议吗?
item1=&item2=value
。谢谢。 - haim770ToString()
实现被定义为返回String.Empty
,因此您可以选择使用DBNull.Value
,从而避免定义EmptyParameter
类的需要。 - Christopher KingRouteCollection.GetVirtualPathForArea(HttpContext,string)
中删除空值?这是什么原因呢?无论如何,感谢你提供的绝佳解决方案!我已经花了整整一天的时间来解决这个问题。 - T-motyUrlParameter.Optional
,因为它比DBNull.Value
更相关,更不容易混淆。 - T-moty