Model binding comma separated query string parameter

Here’s my improved version of Nathan Taylor’s solution used in archil’s answer. Nathan’s binder could only bind sub-properties of complex models, while mine can also bind individual controller arguments. My binder also gives you correct handling of empty parameters, by returning an actual empty instance of your array or IEnumerable. To wire this up, you … Read more

error with decimal in mvc3 – the value is not valid for field

I just stumbled on this again after 2 years. I thought ASP.NET MVC 5 had solved this but looks like it’s not the case. So here goes how to solve the problem… Create a class called DecimalModelBinder like the following and add it to the root of your project for example: using System; using System.Globalization; … Read more

How to make ASP.Net MVC model binder treat incoming date as UTC?

This problem persists in ASP.NET Core 2.0. The following code will resolve it, supporting ISO 8601 basic and extended formats, properly preserving the value and setting DateTimeKind correctly. This aligns with the default behavior of JSON.Net’s parsing, so it keeps your model binding behavior aligned with the rest of the system. First, add the following … Read more

How can I use DateOnly/TimeOnly query parameters in ASP.NET Core 6?

Turns out, there are two solutions: Custom ModelBinder + Swagger configuration Custom TypeConverter (Swagger will automatically see it, and update UI accordingly) I went with TypeConverter, and everything worked! Since .Net team are not planning to add full support for DateOnly/TimeOnly in .Net 6, I’ve decided to create a NuGet to do so: https://www.nuget.org/packages/DateOnlyTimeOnly.AspNet (source … Read more

Custom model binder for a property

override BindProperty and if the property is “PropertyB” bind the property with my custom binder That’s a good solution, though instead of checking “is PropertyB” you better check for your own custom attributes that define property-level binders, like [PropertyBinder(typeof(PropertyBBinder))] public IList<int> PropertyB {get; set;} You can see an example of BindProperty override here.

ViewModel with List and editor templates

Assuming you have the following models: public abstract class TableInputModel { } public class RectangleTableInputModel : TableInputModel { public string Foo { get; set; } } public class CircleTableInputModel : TableInputModel { public string Bar { get; set; } } And the following controller: public class HomeController : Controller { public ActionResult Index() { var … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)