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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:31:18+00:00 2026-05-30T10:31:18+00:00

In my code I have a base class Foo and all my objects inherits

  • 0

In my code I have a base class Foo and all my objects inherits from the Foo object.
So let’s say I have a class like this

public class Bar : Foo {
    public string Heading { get;set; }
}

I have tried to use the ApiControllers put method with dynamic but I get this error http://paste2.org/p/1914054

This is the code I’m using in the ApiController

public void Put(string id, dynamic model) {
    //do stuff
}

If I use a normal controller I can use dynamic to post data. Is it possible to add make the api controller work with dynamic or do I need to build my own model binder?

It sees like some thinks that even in MVC 3 the input parameters can’t be a dynamic but that is not true and that’s why I ask this question. This controller in MVC 3 works just great with dynamic as input parameter.

  • 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-30T10:31:20+00:00Added an answer on May 30, 2026 at 10:31 am

    It sees like some thinks that even in MVC 3 the input parameters can’t
    be a dynamic

    I think so. Let’s take a look at the provided example:

    [HttpPost]
    [ValidateInput(false)]
    public virtual ActionResult Update(dynamic editorModel) {
    
        if (!TryUpdateModel(_model, "CurrentModel")) {
            var parentId = _model.Parent != null ? (string)_model.Parent.Id : null;
            var viewModel = new EditViewModel
            {
                RootModel = _session.Query<IPageModel>()
                    .Where(model => model.Parent == null)
                    .SingleOrDefault(),
                CurrentModel = _model,
                ParentModel = parentId != null ? _session.Load<IPageModel>(parentId) : null,
            };
            return View("edit", viewModel);
        }
    
        UpdateModel(_model);
    
        _model.Metadata.Changed = DateTime.Now;
        _model.Metadata.Published = _model.Metadata.IsPublished ? DateTime.Now : default(DateTime?);
        _model.Metadata.ChangedBy = HttpContext.User.Identity.Name;
    
        _repository.SaveChanges();
        _repository.Refresh(_model);
    
        var page = _model as IPageModel;
    
        if (page.Parent != null) {
            _model = _repository.SingleOrDefault<IPageModel>(m => m.Id == page.Parent.Id);
        }
    
        return RedirectToAction("index", new { model = _model });
    }
    

    Can you point me how/where exactly is this editorModel dynamic variable used inside this controller action?

    And to even further simplify this controller action, it works, because it never never uses the dynamic variable passed as argument. I have simplified it to better illustrate what this action is roughly doing concerning model binding (throwing away of course all the infrastructure noise that we are not interested in here to illustrate the problem):

    [HttpPost]
    public ActionResult Update(dynamic blablabla)
    {
        dynamic model = new MyViewModel();
        UpdateModel(model);
        // at this stage the model will be correctly bound
    
        return View(model);
    }
    

    Inside this action the TryUpdateModel and UpdateModel methods are called on the _model instance variable which is passed in the constructor and is of type IPageModel. ASP.NET MVC cannot possibly know (without a custom model binder of course) the type of your dynamic action argument. Just run this code, put a breakpoint inside the Update action and observe the type of the editorModel variable. It will simply be System.Object. There are no miracles.

    So it’s for me it’s perfectly normal that this works the same in ASP.NET Web API.

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

Sidebar

Related Questions

Suppose I have some code like this: class Base { public: virtual int Foo(int)
Say I have some code like this: class Foo { public: Foo(int v) :
I have code that looks something like this: public class Foo<T> : ObservableCollection<T> {
I have this kind of code: public class Foo { public SomeHandler OnBar; public
Say I have classes Foo and Bar set up like this: class Foo {
I have this code in base class protected virtual bool HasAnyStuff<TObject>(TObject obj) where TObject:class
I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of
I have the following sample code. class bar is derived from the base class
I have written some code that uses attributes of an object: class Foo: def
Given this snippet of code public abstract class Foo { private static SqlConnection _sqlConnection;

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.