What is the correct way to create custom model binders in MVC6?

后端 未结 3 671
生来不讨喜
生来不讨喜 2021-01-15 08:43

I\'m trying to follow the steps in this article using a vNext project and mvc 6. I\'ve been reading through the code here but still a little unsure how to implement this.

3条回答
  •  礼貌的吻别
    2021-01-15 09:24

    Sample model binder: https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CancellationTokenModelBinder.cs

    How to register the binder in Startup.cs

    public void ConfigureServices(IServiceCollection services) 
    { 
        services.AddMvc().Configure(options => 
        { 
            options.ModelBinders.Add(typeof(MyModelBinder)); 
        });
    

提交回复
热议问题