0
私は、サーバーに送信する前にフィールドを必須にしています。このために、私は[必須]モデルの検証にデータ注釈を使用しました。 文字列のデータ型では正常に動作しますが、doubleでは正しく動作しません。jsonに必要なプロパティが見つかりません
doubleタイプのプロパティで何らかの理由で機能しません。
public class ProductMetadata
{
[Required]
public string Barcode { get; set; }
[StringLength(50)]
[Required(AllowEmptyStrings = false, ErrorMessage="Please insert the product name!")]
public string Name { get; set; }
[Range(0, 5000)]
public double ShippingCostPerUnit { get; set; }
[Range(0, 10000)]
public int QuantityForFreeShipping { get; set; }
public Nullable<int> CategoryId { get; set; }
public bool IsDeleted { get; set; }
[Range(0, 1000000)]
[Required(ErrorMessage="Please provide a unit price for the product!")]
public double UnitPrice { get; set; }
}
レスポンスボディは、JSONの応答であり、完成必須フィールドのどれものために、以下の内容があります:
{
"Message":"The request is invalid.",
"ModelState":
{"product":["Required property 'UnitPrice' not found in JSON. Path '', line 1, position 33."],
"product.Barcode":["The Barcode field is required."],
"product.Name":["Please insert the product name!"]
}
}
Iドンここ は、私がモデルのためにしたコードですの名前がとの場合は、バーコードであり、の場合は正しくありません。理由はわかりません。単価。
編集1:
私は[必須]属性を削除し、私は単価の入力を入れた場合は-1、私は適切な検証メッセージが表示され、なぜのために働いていません必要な属性?
編集2:要求ペイロード(もProductMetadataクラスを更新):
{IsDelete: false, CategoryId: 1}
CategoryId: 1
IsDelete: false
すべてのヘルプは歓迎です!ありがとう!
リクエストペイロード(JSON)を共有できますか? – Paritosh
@Paritosh質問を編集しました – sixfeet