Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:03:23+00:00 2026-05-25T06:03:23+00:00

I have a very simple implementation of the DefaultModelBinder, I need it to fire

  • 0

I have a very simple implementation of the DefaultModelBinder, I need it to fire some custom validation.

public class MyViewModelBinder : DefaultModelBinder 
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        ModelStateDictionary modelState = bindingContext.ModelState;
        var model = (MyViewModel)base.BindModel(controllerContext, bindingContext);

        var result = ValidationFactory.ForObject<MyViewModel>().Validate(model);

        CustomValidation(result, modelState);

        return model;
    }
}

MyViewModel is a public sealed class.
The model binder is registered in the Global.asax this way:

ModelBinders.Binders.Add(typeof(MyViewModel), new MyViewModelBinder());

The problem is that the model is never populated! But the MVC default model binder (I remove the registration in global.asax) works fine.

This is the view HTML:

    <table>
        <tr>
            <td><label for="Name">Name</label></td>
            <td><input id="Name" name="Name" type="text" value="" /></td>
        </tr>
        <tr>
            <td><label for="Code">Code</label></td>
            <td><input id="Code" name="Code" type="text" value="" /></td>
        </tr>
    </table> </div>

Every field matches a property of the model.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:03:24+00:00Added an answer on May 25, 2026 at 6:03 am

    From the information you provided I am unable to reproduce the problem. Here’s what I did.

    View model:

    public sealed class MyViewModel
    {
        public string Name { get; set; }
        public string Code { get; set; }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            // at this stage the model is populated perfectly fine
            return View();
        }
    }
    

    Index View:

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <% using (Html.BeginForm()) { %>
            <table>
                <tr>
                    <td><label for="Name">Name</label></td>
                    <td><input id="Name" name="Name" type="text" value="" /></td>
                </tr>
                <tr>
                    <td><label for="Code">Code</label></td>
                    <td><input id="Code" name="Code" type="text" value="" /></td>
                </tr>
            </table>
            <input type="submit" value="OK" />
        <% } %>
    </body>
    </html>
    

    Model binder:

    public class MyViewModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var model = (MyViewModel)base.BindModel(controllerContext, bindingContext);
    
            // at this stage the model is populated perfectly fine
            return model;
        }
    }
    

    So now the question is, how does your code differs than mine and what is it in those CustomValidation and Validate methods?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a very simple custom object pictureData . Here is the .h
i have very simple problem. I need to create model, that represent element of
I have a very simple implementation of MFMailComposeViewController. It works very well - I
I have a very simple AsyncTask implementation example and am having problem in testing
We have an XML file with a very simple implementation of XLink : <root
I have a very simple scenario: My iPhone application contains a UIViewController implementation which
I seem to have a problem with my very simple implementation of a file
I have a very simple class: People: class People { private string LastName =
I have a very simple queue implementation that wraps a fixed array. It contains
I have a very simple class (shown below), however every time I run it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.