Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何解决Angular8中输入字符串格式不正确的问题?_C#_Angular_Asp.net Core - Fatal编程技术网

C# 如何解决Angular8中输入字符串格式不正确的问题?

C# 如何解决Angular8中输入字符串格式不正确的问题?,c#,angular,asp.net-core,C#,Angular,Asp.net Core,在我的asp.NETCore3.1中,我有一个返回aws维护类型列表的方法,我在angular 8项目中使用api 当我使用postman时,我得到的结果是json [ "c5n.4xlarge", "m2.2xlarge", "t3.xlarge", "m5dn.8xlarge", .......... ] 但在chrome的网络标签中,我得到了回复 当我试图发布(它在后端工作)时,它会抛出错误 输入字符串的格式不正确 我看到它没有抓取值并设置为未定

在我的asp.NETCore3.1中,我有一个返回aws维护类型列表的方法,我在angular 8项目中使用api

当我使用postman时,我得到的结果是json

[
    "c5n.4xlarge",
    "m2.2xlarge",
    "t3.xlarge",
    "m5dn.8xlarge",
    ..........
]
但在chrome的网络标签中,我得到了回复

当我试图发布(它在后端工作)时,它会抛出错误

输入字符串的格式不正确

我看到它没有抓取值并设置为未定义。如何使json结果类似于未编号的邮递员结果。不知道这是不是原因。但在响应部分,它是普通的json。可能是因为多个阵列

另一个关于输入字符串的主题格式不正确,但它与整数问题有关,但在我的例子中,我只需要字符串

我的服务://这也是opentack的类似方法,效果很好

createAws(model: any, projectId: number, instanceType?: any) {
    return this.http.post(`${this.baseUrl}servers/${projectId}?i 
   instanceType=${instanceType}`, model);
  }
我的组成部分://

selectInstanceHandler(event: any){
    this.selectedInstance = event.target.value;
  }



createAws(instanceType: any){
    this.subs.add(this.cvmService.createAws(this.model,this.projectId,instanceType).subscribe(
      x => {
        this.model = x;
        this.alertify.success("successfully added new Server");
      },
      error => {
        this.alertify.error("\n" + error);
      }
    ))
  }
我的html:

      <div class="row" *ngIf="type == 'AWS'">
        <div class="col-3 mt-3 labelText">
          <span class="spanText">Aws Instance Type</span>
        </div>
        <div class="col-9">
          <mat-form-field class="example-full-width">
            <mat-label>Please select intance type</mat-label>
            <select matNativeControl required name="awsInstanceType" 
             [(ngModel)]="model.awsInstanceType"
              (change)="selectInstanceHandler($event)">
              <option value="-1" disabled> </option>
              <option *ngFor="let item of aws">
                {{ item }}
              </option>
            </select>
          </mat-form-field>
        </div>
      </div>

结果没有编号,这只是chrome格式化数据的方式,使其易于阅读。这就是为什么它被称为预览选项卡


检查“响应”选项卡,响应只是字符串数组(即未编号)

是,我作为邮递员检查了它是正常结果,但当我发布时,它设置为“未定义”,并且抛出的输入字符串格式不正确。@ArzuSuleymanov然后用示例字符串发布该代码。该错误的原因似乎与您想象的不同。@Fildor有趣的是,它在postman中工作,没有任何问题。请在chrome dev工具的函数selectInstanceHandler()中输入断点,然后检查事件的值。您可能无法获得正确的事件。正如我所说的,使用this.model.awsInstanceType,您可能不需要选择InstanceHandler乐于帮助:-)
{{url}}/api/servers/22?instanceType=r5a.large