You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ServiceStack API Explorer表单页数组字段不显示的解决咨询

ServiceStack API Explorer中GET请求数组字段显示输入框的解决方案

问题场景

你定义了如下GET请求DTO:

public partial class SelectTiers : IReturn<SelectTiersResponse>, IGet
{
    public string? SearchText { get; set; }

    public string[]? Sort { get; set; }

    public int? Skip { get; set; }

    public int? Take { get; set; }
}

但API Explorer页面仅展示SearchText、Skip、Take的输入框,Sort数组字段未显示。尝试添加[Input(Type = "text")]注解无效,当前使用ServiceStack 6.11版本。

可行解决方案

方案1:生成多输入项控件

给Sort字段添加[Input(Type = "text", AllowMultiple = true)]注解,API Explorer会渲染出可动态添加多个输入框的控件,每个输入框对应数组的一个元素:

public partial class SelectTiers : IReturn<SelectTiersResponse>, IGet
{
    public string? SearchText { get; set; }

    [Input(Type = "text", AllowMultiple = true)]
    public string[]? Sort { get; set; }

    public int? Skip { get; set; }

    public int? Take { get; set; }
}

方案2:单输入框接受逗号分隔值

如果希望用单个输入框接受逗号分隔的字符串,可结合[QueryParam]指定集合格式,ServiceStack会自动将逗号分隔的字符串解析为string[]:

public partial class SelectTiers : IReturn<SelectTiersResponse>, IGet
{
    public string? SearchText { get; set; }

    [Input(Type = "text")]
    [QueryParam(CollectionFormat = CollectionFormat.Csv)]
    public string[]? Sort { get; set; }

    public int? Skip { get; set; }

    public int? Take { get; set; }
}

这两种方式都能让API Explorer正确显示Sort字段的输入控件,同时ServiceStack会正常解析请求参数为数组类型。

内容的提问来源于stack exchange,提问作者Adam Bross

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 16:00:04