Joe*_*aus 5 parameters asp.net-mvc actionlink query-string razor
我正在使用Html.ActionLink(string linkText, string actionName, object routeValues)
重载将一些参数发送到操作方法..
有时我需要传递一个空参数值,如: ?item1=&item2=value
我指定的匿名类型创建,并通过作为帕拉姆routeValues
,但两者null
并string.Empty
导致URL省略了空item1
PARAM。
new { item1 = null, item2 = "value" }
new { item1 = string.Empty, item2 = "value" }
new { item1 = "", item2 = "value" }
// all result in:
?item2=value
Run Code Online (Sandbox Code Playgroud)
我可以手动创建 URL,但我想使用辅助方法。
建议?
创建一个EmptyParameter
类,如下所示:
public class EmptyParameter
{
public override string ToString()
{
return String.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
然后:
@Html.ActionLink("Action",
"Controller",
new { item1 = new EmptyParameter(), item2 = "value" });
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1850 次 |
最近记录: |