【发布时间】:2020-07-21 20:30:13
【问题描述】:
我是 ASP.NET Core 新手,刚刚学习一些新概念...
当我使用生成链接时
public static string GetUriByPage (this Microsoft.AspNetCore.Routing.LinkGenerator generator,
string page, string handler, object values,
string scheme, Microsoft.AspNetCore.Http.HostString host,
Microsoft.AspNetCore.Http.PathString pathBase = default,
Microsoft.AspNetCore.Http.FragmentString fragment = default,
Microsoft.AspNetCore.Routing.LinkOptions options = default);
values 字段将输入作为object 类型。如果我尝试插入一个字符串作为对象,它将采用Length 字符串属性的值而不是字符串变量的值。我假设values 字段获取对象的所有公共属性,这就是它的工作原理,但是我如何能够只传入字符串值而不是公共属性?
我正在尝试我只是想了解为什么会这样,documentation 没有太多关于幕后行为的信息。
测试代码
// Create a new entry in the hash table
var record = _context.HashRecords.Add(new Data.HashRecord {
FullName = user.FullName,
Representative = repName,
Hash = GetUniqueKey(8)
});
_context.SaveChangesAsync();
string generatedLink = _linkGenerator.GetUriByPage("/Page",
handler: null,
values: record.Entity,
scheme: _httpContextAccessor.HttpContext.Request.Scheme,
host: _httpContextAccessor.HttpContext.Request.Host);
【问题讨论】:
-
是的,那是文档,但这并没有解释为什么“values”参数在传入字符串而不是字符串的值时返回 String.Length。我怀疑这不是专门的 Asp.Net Core 问题,而是我对 C# 不了解的问题...
标签: c# asp.net-core