In an ASP.NET Core project, I do the following:
public async Task<IActionResult> Get(ProductModel model) { } public class ProductModel { public Filter<Double> Price { get; set; } }
I have a base filter class and RangeFilter as follows:
public class Filter<T> { } public class RangeFilter<T> : Filter<T> { public abstract Boolean TryParse(String value, out Filter<T> filter); }
I am passing the string ( "[3.34;18.75]" ) to the action as a price.
I need to create a ModelBinder where I use the TryParse method to try to convert this String to RangeFilter<Double> to define the ProductModel.Price property.
If TryParse fails, for example, returns false , the ProductModel.Price property becomes null.
How can I do that?
c # asp.net-core
Miguel moura
source share