小编Jos*_*ers的帖子

访问内部API控制器

有没有办法从另一个类调用应用程序 API 控制器而不使用 API 的 url?

例如我在“personContoller”中有这个方法

    public async Task<ActionResult> GetPersonRecord(string id)
    {
        Person person;
        var link = "api/entity/Person/" + id + "?format=json";
        string results = await OneIMAction(link);
        person = JsonConvert.DeserializeObject<Person>(results);
        string json = JsonConvert.SerializeObject(person, Formatting.Indented);
        return Content(json, "application/json");
    }
Run Code Online (Sandbox Code Playgroud)

如何在同一应用程序中的另一个 C# 类中访问此方法的 JSON 结果,而无需使用 Web 请求?那可能吗?

.net c# asp.net-mvc asp.net-mvc-5

2
推荐指数
1
解决办法
5834
查看次数

C# 对列表和列表进行重复数据删除并合并列表

使用列表对列表进行重复数据删除的最佳方法是什么?粗略类示例:

Class CustomType{
 string prop1
 string prop2
 string prop3
 int quantity
 List<AnotherCustomType> serials
}
Run Code Online (Sandbox Code Playgroud)

所以我有一个 CustomType 对象列表。我开始尝试做一个小组,但被挂在名单上。我需要将列表中的项目与相同的 prop1 和 prop2 组合起来,并组合它们的列表(序列)和组合数量。

我开始走这条路...

 List<CustomType> c = (from x in items
                                  group x by new {
                                      x.prop1, x.prop2
                                  } into y
                                  select new CustomType {
                                  quantity = y.Sum(z => z.quantity),
                                  prop1 = y.prop1,
                                  prop2=y.prop2,
                                  prop3 = y.prop3,
                                  serials= ????? how do I combine the lists
}

Run Code Online (Sandbox Code Playgroud)

我离题了吗?

.net c# linq

2
推荐指数
1
解决办法
47
查看次数

Angular 9 mat-table 和 ExpressionChangedAfterItHasBeenCheckedError

我有一个 Angular 9,打开了 Ivy,组件有多个垫子表。一张表的行中的输入字段绑定到反应式表单。我将表绑定到表单数组。这很好用...但是,当我加载带有值的formarray时,我得到了有趣的“ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。'ng-valid'的先前值:'true'。当前值:'false'”错误。

另外,如果我在组件上设置changeDetection:ChangeDetectionStrategy.OnPush,它工作正常,但我显然失去了更改检测......

桌子

这是我的设置(精简):

反应形式:

quoteForm = new FormGroup({
    QuoteNumber:new FormControl(''),
    ContractTerm:new FormControl(''),
    ContractStartDate:new FormControl(''),
    QuoteName: new FormControl('', Validators.required),
   ...
    Items: this.fb.array([])
  });



async ngOnInit(): Promise<void> {
  ...
  this.QuoteItems = await this.CIM.GetQuoteItems(this.CurrentQuoteNumber);
  const itemsArray = this.quoteForm.get('Items') as FormArray;
  ...
  this.QuoteItems.forEach(item => {
      let NewObj = this.fb.group({
      isNew:false,
     ...
     });
     ...
     itemsArray.push(NewObj);
   });    
  }

  this.ItemdataSource=new MatTableDataSource(this.quoteForm.get('Items').value);
  this.ItemdataSource.paginator = this.paginator.toArray()[0];

}
Run Code Online (Sandbox Code Playgroud)

表格 HTML(已修剪):

<table mat-table [dataSource]="ItemdataSource" multiTemplateDataRows formArrayName="Items"> 
...
 <tr mat-header-row *matHeaderRowDef="ItemColumns"></tr>
 <tr mat-row *matRowDef="let row; columns: ItemColumns;" class="element-row" [class.expanded-row]="expandedElement …
Run Code Online (Sandbox Code Playgroud)

angular-material angular mat-table

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