我正在使用Html.ActionLink(string linkText, string actionName, object routeValues)
重载将一些参数发送到Action方法..
有时我需要传递一个空的参数值,如:?item1=&item2=value
我在我创建的匿名类型中指定了参数,并以routeValues
传递,但null
和string.Empty
都会产生一个省略空item1
的网址PARAM。
new { item1 = null, item2 = "value" }
new { item1 = string.Empty, item2 = "value" }
new { item1 = "", item2 = "value" }
// all result in:
?item2=value
我可以手动创建URL,但我想使用帮助方法。
建议?
答案 0 :(得分:4)
创建一个EmptyParameter
类,如下所示:
public class EmptyParameter
{
public override string ToString()
{
return String.Empty;
}
}
然后:
@Html.ActionLink("Action",
"Controller",
new { item1 = new EmptyParameter(), item2 = "value" });