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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:51:44+00:00 2026-06-04T19:51:44+00:00

I started using MVC recently and I’m getting little disappointed. Instead of helping me,

  • 0

I started using MVC recently and I’m getting little disappointed. Instead of helping me, the framework is getting in my way.

I’m trying to write a controller action like this (pseudo code)

ActionResult Save(long id, string whichForm)
{
    if (whichForm == "A")
    {
        var vm = CreateModel(Request.Form);
        if (!TryValidate(vm))
            return View(vm);
        else
            return RedirectToRoute("Success");
    }
    else ....
}

Basically I’d like to have control over when my view-model is constructed and when it is validated. Is this possible? How can I implement CreateModel method? Consider I may want to create several different view-models within this controller action.

*Rant: I don’t really understand why view-model binding and validation are mixed together in DefaultModelBinder. Seems like code smell. Specially when it’s hard to override this behaviour.

  • 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-06-04T19:51:46+00:00Added an answer on June 4, 2026 at 7:51 pm

    You can create and bind to an existing model at your discretion:

    public ActionResult Save(long id, string whichForm)
    {
        if (whichForm == "A")
        {
            var vm = new FormAViewModel();
    
            if (!TryUpdateModel(vm))
                return View(vm);
            else
                return RedirectToRoute("Success");
        }
        // else ....
    }
    

    You also have the option of creating your own IModelBinder, if you want complete control over the binding process. You can replace the default model binder, or you can register specific IModelBinder implementations for specific types. I would suggest, however, that unless your binding logic is simple, you will probably want to derive your custom model binder from DefaultModelBinder and just override the parts you don’t like.

    I hate to leave a troll-ish comment, but 9 times out of 10 the reason someone feels a framework is getting in their way is because they don’t yet understand how to properly use it. Here is an article with general tips on model binding.

    As to your rant: Validation and Binding are separate, however, the default model binder does trigger validation. The reason for this is to allow your application to gracefully handle problems binding to missing/invalid/incomplete values, rather than allowing binding to fail silently or throwing exceptions.

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

Sidebar

Related Questions

I recently started using the Yii framework trying to learn a little bit more
Recently I've started to write on asp.net mvc framework. I have a problem. I
I recently started looking into building web applications using .NET MVC and I stumbled
I've just recently started to build a web site using ASP.NET - MVC 4,
Hey... I started using Javascript MVC SproutCore Framework (sproutcore.com) and I found it impressive.
Following this tutorial (http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application), I learned how to save data and do concurrency checks
i've started working with ASP.NET MVC and using Entity Framework, concretely with SQLite db,
I'm just getting started with ASP.NET MVC. I'm going to be using JQuery on
We have started using MVC framework and now we are bit confused where to
I have recently started using ASP.Net MVC 3 RC 2 and have attempted to

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.