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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:31:19+00:00 2026-05-27T02:31:19+00:00

I have a view with multiple forms on it. These forms have partial views

  • 0

I have a view with multiple forms on it. These forms have partial views which are added using Html.RenderPartial(). I want to be able to distinguish between the models in a single actionResult thusly:

    [HttpPost]
    public ActionResult LogOn(dynamic Model, string returnUrl)
    {
        if (Model is RegisterModel)
        {
            Register((RegisterModel)Model, returnUrl);
        }
        return View();
    }

Is there any reason why this doesn’t work? I have also tried typing Model as an object instead of a dynamic but that didn’t help either. Model.GetType() always returns object, and Model is RegisterModel always returns false. What am I missing about MVC3’s behavior that I need to understand here? Thank you for your time

  • 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-27T02:31:19+00:00Added an answer on May 27, 2026 at 2:31 am

    At first, why dont create different Action Methods for different ModelTypes ?
    This would result in better performance and better “seperation of concern.”
    But if you want to do this the way you describe, try this…

    Maybe this sounds strange but

    It is statically-typed as a dynamic type.

    You can create a Custom Model Binder that tryes to bind your
    POST or GET informations to the type that you want.

    public class MyCustomModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            object result;
            HttpRequestBase request = controllerContext.HttpContext.Request;
    
            // custom logic sample
            if (request.Params["ParamName"].ToString() == "xyz")
            {
                result = new RegisterModel();
                result.Propertie1 = request.Params["Propertie1"];
            }
            else
            {
                // create another model
            }
    
            return result;
        }
    }
    

    Then you can do this.

    [HttpPost]
    public ActionResult LogOn([ModelBinder(typeof(MyCustomModelBinder))] object Model, string returnUrl)
    {
        if (Model is RegisterModel)
        {
            Register((RegisterModel)Model, returnUrl);
        }
        return View();
    }
    

    Scott Hanselman wrote a nice Blog Post about the dynamic keyword:
    C# 4 and the dynamic keyword

    More informations about IModelBinder: ASP.NET MVC Custom Model Binding

    hope this helps

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

Sidebar

Related Questions

I have a view model for a view which displays multiple forms on the
I have senario in which one view and view has binding with multiple ViewModel.
I have multiple hidden form fields which store values about the the current view
I have multiple pages containing the same partial view. The partial contains a form
How do I pass variables to multiple partial views within a view? My idea
Is it possible to have multiple view of the same display object? (e.g. same-computer
I have a java class: it.eng.ancona.view.RuoliView$TabElaborazioneFattureValidazione$ElencoDettaglioElaborazioneFattureValidazione$RigaElencoDettaglioElaborazioneFattureValidazione It's so long for multiple inner class. If
I have a for loop that creates multiple UIImageViews that I add to self.view
I have a view using a master page that contains some javascript that needs
I have multiple MVC 3 forms that need form validation on certain fields (mostly

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.