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 890709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:46:34+00:00 2026-05-15T13:46:34+00:00

I want to create a custom modelbinder which validates the bounded model. I have

  • 0

I want to create a custom modelbinder which validates the bounded model. I have found several examples of this and it works as it should. But I want to also to be able to send the user back to the page he came from if there is errors in the model.

Is this possible to do and are there any obvious side effects by doing this?

What I want to achieve is that the controller always gets valid commands, so I do not need to check for model.IsValid() in the action method.

  • 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-15T13:46:35+00:00Added an answer on May 15, 2026 at 1:46 pm

    What you try to do looks good, but it won’t work. There’re too many restrictions.

    1. Usually, only controller can decide where to redirect in case of an error. You can use additional attributes like [OnError(“Action”)] but this looks like workarounds.
    2. Form doesn’t post all data. For example, dropdown lists, auxiliary values have to be filled by controller. You can probably use action filters for this but this is once again looks like a hack.

    You can setup global action filter (on base controller) that will check for model errors (that binder sets) and redirect (setup .Result). But this is convoluted and requires too much extra “code” – attributes, etc., that is then hard to track and relate to real application logic. And it becomes too restrictive soon (see law of leaky abstraction), when you need not just simple action name on error redirect, etc.

    This looks much simpler when done like this:

    public ActionResult PostAction(ViewModel data)
    {
       if (!ModelState.IsValid)
          return View("GetAction", data.WithDropDownList(repository.GetProducts()));
    
    }
    

    In the above example, controller has the control over the workflow, just as it should be. It also has freedom to perform additional verification/setup. You can still use as much infrastructure as possible – model binders to provide ModelState errors, etc – but only controller should have the final decision on the input and output.

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

Sidebar

Related Questions

I want to create a custom toolbar control (descendant TToolBar) which should have some
I want to create custom templated control which controls inside of template coluld be
What I have is a model which has one of it's attributes dynamic. This
I want to create custom NANT files. To do this, I use C# to
I want to create custom Textbox control in asp.net.But i have one doubt when
I want to create a simple game.I need this information how to create custom
I want to create a custom button in ActionScript. This is my code: import
I want to create a custom drawable for RadioButton's button drawable. I have created
I want to create a custom control in C#. But every time I have
i want to create custom grid column with radio button in it. i have

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.