I have a strange situation, and none of the existing solutions help I have this model in the .NET Framework Web API public partial class RequestData { public int Id { get; set; } [Required(AllowEmptyStrings = false)] public string AccountName { get; set; } [Required(AllowEmptyStrings = false)] public string VendorName { get; set; } [Required] public string Memo { get; set; } public Nullable<bool> IsToBePrinted { get; set; } [Required] public string AccountType { get; set; } [Required] public Nullable<double> Amount { get; set; } public Nullable<bool> IsProcessed { get; set; } public string Ticket { get; set; } public string Response { get; set; } public Nullable<System.DateTime> Updated { get; set; } [Required] public Nullable<int> RequestType { get; set; } [Required] public string TxnId { get; set; } [Required] public string EditSequence { get; set; } [Required] public string ListID { get; set; } [Required] public string TxnLineId { get; set; } }
[HttpPost] public ActionResult PostNewRequest([FromBody] RequestData requestData) { try { if (!ModelState.IsValid) { //Your code if the field is invalid } else { //Your code if the field is valid }
public class ValidateModelAttribute : ActionFilterAttribute { public override void OnActionExecuting(HttpActionContext actionContext) { if (!actionContext.ModelState.IsValid) { actionContext.Response = actionContext.Request.CreateErrorResponse( HttpStatusCode.BadRequest, actionContext.ModelState); } } }
using RequestData = QuickbooksDesktopAPI.Models.RequestData;
[Required] public Nullable<double> Amount { get; set; }
[Required] public double Amount { get; set; }
Amount
Nullable<double>
null
double
0.0
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)