如何强制 Null 表单元素为零我有以下模型类:-
public partial class MemoryInfo
{
public long WORKSTATIONID { get; set; }
public Nullable<long> TOTALMEMORY { get; set; }
public Nullable<long> FREEMEMORY { get; set; }
public Nullable<long> VIRTUALMEMORY { get; set; }
public Nullable<long> FREEVIRTUALMEMORY { get; set; }
public virtual SystemInfo SystemInfo { get; set; }
}
目前我正在使用模型类来构建 API 调用,如下所示:-
query["ramSize"] = Request.Form["SystemInfo.MemoryInfo.TOTALMEMORY"];
query["virtualCapacity"] = Request.Form["SystemInfo.MemoryInfo.VIRTUALMEMORY"];
query["proSpeed"] = Request.Form["SPEED"];
string apiurl = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiURL"];
var url = new UriBuilder(apiurl);
但目前如果用户将 ramSize 字段留空,它将作为 Null 值发送,API 将忽略这些值,而我需要以下场景;如果 ramSize 字段为空,则提交零值。
谁能告诉我我怎么能这样做?谢谢