我不确定绑定和更新动态生成复选框的模型的正确方法.(这是一个最初使用Yeoman生成器创建的Angular 2的ASP.NET Core项目)或者我刚刚发现的一个简单的复选框.
下面是剥离代码,它有一个设施和时间段.每个设施可以有多个时隙.时间段复选框列表显示正常.初始数据表明只应检查一个时隙.但是当我加载一个设施时,所有的时间段都会被检查.它们没有像我预期的那样与ngModel绑定.
代码说明我有两个来自api的对象(设施和时间段),我绑定到接口.为简单起见,它们的属性显着降低:
export interface IFacility {
id: number,
name: string,
haselectric: boolean,
timeslotids: number[],
timeslots: ITimeslot[]
}
export interface ITimeslot {
id: number,
timeslotname: string
}
Run Code Online (Sandbox Code Playgroud)
这是Timeslots的JSON数据:
[{"id":1,"timeslotname":"Daily"},{"id":2,"timeslotname":"Hourly"},{"id":4,"timeslotname":"Market"}]
Run Code Online (Sandbox Code Playgroud)
这是在更新之前单个Facility的JSON数据:
{"id":2,"name":"Clements Building","haselectric":true,"timeslotids":[1],"timeslots":[{"id":1,"timeslotname":"Daily"}]}
Run Code Online (Sandbox Code Playgroud)
用于编辑设施的组件(facility.component.html):
<form #form="ngForm" (ngSubmit)="submitForm()" *ngIf="formactive">
<input type="hidden" [(ngModel)]="updatedfacility.id" #id="ngModel" name="id" />
<div class="form-group">
<label for="name">Facility Name *</label>
<input type="text" class="form-control input-lg" [(ngModel)]="updatedfacility.name" #name="ngModel" name="name" placeholder="Facility Name *">
</div>
<div class="form-group">
<label for="exhibitspaces">Has Electric *</label>
<input type="checkbox" class="form-control input-lg" [(ngModel)]="updatedfacility.haselecric" #haselectric="ngModel" name="haselectric">
</div> …Run Code Online (Sandbox Code Playgroud) 我的项目在运行时找不到服务引用端点。我相信这是由于我的 Startup.cs 中的注入不正确。我是 appsettings.json 和 Startup.cs 配置方法的新手,但已经成功地在 Startup.cs 中确定了我的类库和 Dbcontext 的范围。
请注意,如果有所不同, 此 VS 解决方案包含一个类库和一个 .NET/angular2 Web 项目。对服务的调用是从 angular 网站向 Web API 发起的,后者调用实际处理发生的类库上的方法。
服务引用“CybersourceTrxnProcessor”出现在我的类库项目中(参见图片),并且 ITransactionProcessor 已公开并可访问(即代码提示工作完美)。Web 项目在解决方案资源管理器中没有服务引用。
当我添加引用时,这些部分被添加到 app.config 文件(见下文),我将它们复制到 web 项目中的 web.config。
如何在 appsettings 和 Startup 中“重新创建”web.config 设置?
尝试处理测试付款时,这行代码抛出异常:
TransactionProcessorClient proc = new TransactionProcessorClient("ITransactionProcessor");
Run Code Online (Sandbox Code Playgroud)
我也试过在之前手动定义端点,但同样的错误结果:
System.ServiceModel.EndpointAddress theendpoint = new System.ServiceModel.EndpointAddress("https://ics2wstesta.ic3.com/commerce/1.x/transactionProcessor");
TransactionProcessorClient proc = new TransactionProcessorClient("ITransactionProcessor", theendpoint);
Run Code Online (Sandbox Code Playgroud)
这是错误:
尝试处理您的付款时发生异常。请再试一次。在 ServiceModel 客户端配置部分中找不到名称为“ITransactionProcessor”且合同为“CybersourceTrxnProcessor.ITransactionProcessor”的端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素。
这是我在 Visual Studio 中向项目添加服务引用时生成的配置文件(并且与旧 MVC 项目中的内容相匹配):
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ITransactionProcessor">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="ITransactionProcessor1" />
</basicHttpBinding> …Run Code Online (Sandbox Code Playgroud)