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

  • Home
  • SEARCH
  • 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 7076463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:18:05+00:00 2026-05-28T06:18:05+00:00

My understanding is that ASP.NET MVC only allows you to POST objects to Actions

  • 0

My understanding is that ASP.NET MVC only allows you to POST objects to Actions in the Controller, where the Action’s arguments accept the posted object as a Concrete class.

Is there any way around this, or a good alternative?

In my case, I have an action which accepts an interface as an argument:

public ActionResult SaveAdjustment(IModel model)
{
    switch (model.SubsetType)
    {
        // factory like usage
    }
}

And for this action, I have numerous views, all strongly typed to objects that implement IModel, all which I want to be able to post to this one method.

Of course, running this give me the error:

Cannot create an instance of an interface

Is there a nice work around to this? Or do I need to create an Action method for each and send them over to a method like this?

  • 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-28T06:18:05+00:00Added an answer on May 28, 2026 at 6:18 am

    Although I mentioned this as a possible solution in my original question, its the solution I have gone with in the end and I actually quite like it now. This way I didn’t need to touch the model default binding implementation and I think this approach is a more readable/understandable approach than what I was originally asking for.

    In case its not clear why I wanted to go for this approach, I have added an example of how I can use this for its OO benifits.

        [HttpPost]
        public ActionResult SaveModelA(ModelA model)
        {
            return SaveModel(model);
        }
    
        [HttpPost]
        public ActionResult SaveModelB(ModelB model)
        {
            return SaveModel(model);
        }
    
        private ActionResult SaveModel(IModel model)
        {
            IExampleService exampleService;
            IRequirements requirements;
    
            switch (model.SubsetType)
            {
                case SubsetType.ModelA:
                    myService = new ModelAService();
                    requirements = new ModelARequirements
                    {
                        ModelASpecificProperty = "example"
                    };
                    break;
                case SubsetType.ModelB:
                    myService = new ModelBService();
                    requirements = new ModelBRequirements
                    {
                        ModelBSpecificProperty1 = "example",
                        ModelBSpecificProperty2 = "example2",
                        ModelBSpecificProperty3 = "example3"
                    };
                    break;                
                default:
                    throw new InvalidEnumArgumentException();
            }
    
            var serviceResonse = exampleService.ExecuteExample(model, requirements);
    
            return RedirectToAction("Index", new
            {
                ExampleData = serviceResponse.ExampleDate
            });
        }
    

    In case it isn’t clear in the code:

    ModelA : IModel
    ModelB : IModel
    ModelARequirements : IModelRequirements
    ModelBRequirements : IModelRequirements
    ModelAService : IExampleService
    ModelBService : IExampleService
    
    // and IModel defines a property SubsetType SubsetType { get; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to modify asp.net mvc's controller registery so that I can create
My original understanding was that the asp.net page lifecycle is run once for all
It's my understanding that StackOverflow (SO) was built using ASP.NET. What surprised me is
I'm working on an ASP.NET MVC web application that will be deployed across multiple
Possible Duplicate: Streaming large file uploads to ASP.NET MVC To my understanding, when a
I have an ASP.NET MVC 3 project that I just created using the project
Perhaps this is a naive question. In my understanding, ASP.NET MVC cannot work with
I have an ASP.NET MVC site that contains a WCF SVC that is hosted
I've been working on an ASP.net MVC project that uses checkbox HTML Helpers in
I have an ASP.NET MVC 3 application where users can post suggestions along the

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.