【发布时间】:2020-09-06 07:18:11
【问题描述】:
我正在尝试按照建议的here 从 URL 获取查询字符串,但我得到了 NullReferenceException。我的代码与链接帖子中的代码之间的唯一区别是我的代码是静态的,我看不出这会如何导致错误。
public static class Extensions
{
//Other helper methods
[Inject]
public static NavigationManager MyNavigationManager { get; set; }
public static string GetQueryParm(string parmName)
{
//Null Reference Exception is called on the line below
var uriBuilder = new UriBuilder(MyNavigationManager.Uri);
var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);
return q[parmName] ?? "";
}
}
我这样称呼这个方法:
else if (date == null | string.IsNullOrWhiteSpace(Extensions.GetQueryParm("d")))
{
date = DateTime.Today.ToString("yyyy-MM-dd");
}
【问题讨论】:
-
旁注:你想要
||,而不是布尔逻辑中的|。
标签: c# dependency-injection blazor nullreferenceexception