小编MKa*_*zyk的帖子

linq查询从对象列表中返回不同的字段值

class obj
{
    int typeID; //10 types  0-9 
    string uniqueString; //this is unique
}
Run Code Online (Sandbox Code Playgroud)

假设有包含100个obj元素的列表,但只有10个唯一的typeID.
是否可以写一个LINQ查询从objs列表中返回10个唯一的int?

c# linq

78
推荐指数
6
解决办法
17万
查看次数

在核心 3.0 中将视图渲染为字符串:找不到与 ActionContext 关联的 IRouter

我想要的是:

在我的应用程序中,我想为我的电子邮件使用模板。不幸的是,我之前在另一个项目中使用的代码不再起作用。

抛出的错误:

Could not find an IRouter associated with the ActionContext. 

If your application is using endpoint routing then you can get a IUrlHelperFactory with dependency injection 
and use it to create a UrlHelper, or use Microsoft.AspNetCore.Routing.LinkGenerator.'
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决这个问题,因为我找不到任何方法来注入IUrlHelper. 我不确定为什么甚至需要这样做,因为无论如何它都不在视图中。

字符串渲染方法:

Could not find an IRouter associated with the ActionContext. 

If your application is using endpoint routing then you can get a IUrlHelperFactory with dependency injection 
and use it to create a UrlHelper, or use Microsoft.AspNetCore.Routing.LinkGenerator.'
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-3.0

10
推荐指数
1
解决办法
4328
查看次数

如何在.net core中使用反射通过名称查找类的名称空间?

我有一个仅包含类名称的字符串列表。我需要使用 Activator 创建它们的实例,但它们都可以位于不同的命名空间中。类将来可以移动到另一个名称空间中,因此我无法对其进行硬编码。

c# reflection asp.net-core

4
推荐指数
1
解决办法
5174
查看次数

标签 统计

c# ×3

asp.net-core ×2

asp.net-core-3.0 ×1

linq ×1

reflection ×1