On an ASP.NET Core project I have the following action:
public async Task<IActionResult> Get(ProductModel model) {
}
public class ProductModel {
public Filter<Double> Price { get; set; }
}
I have a Filter base class and a 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 a String ("[3.34;18.75]"
) to the Action as Price.
I need to create a ModelBinder
where I use the TryParse
method to try to convert that String
into a RangeFilter<Double>
to define the ProductModel.Price
property.
If TryParse
fails, e.g., returns false
then the ProductModel.Price
property becomes null.
How can this be done?