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

The Archive Base Latest Questions

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

The model binding worked fine until i implemented interfaces on top of the following

  • 0

The model binding worked fine until i implemented interfaces on top of the following classes:

public class QuestionAnswer : IQuestionAnswer
    {

        public Int32 Row_ID { get; set; }
        public Int32 Column_ID { get; set; }
        public String Value { get; set; }

    }

    public class HiddenAnswer : IHiddenAnswer
    {

        public Int32 Hidden_Field_ID { get; set; }
        public String Hidden_Field_Value { get; set; }

    }

    public class SurveyAnswer : ISurveyAnswer
    {

        public string SessionID { get; set; }

        public List<IQuestionAnswer> QuestionAnswerList { get; set; }

        public List<IHiddenAnswer> HiddenAnswerList { get; set; }

        public SurveyAnswer()
        {
            QuestionAnswerList = new List<IQuestionAnswer>();
            HiddenAnswerList = new List<IHiddenAnswer>();
        }
    }

Now that the interfaces are there, i get a 500 (Internal Server Error)

The javascript that i use to model bind is the following:

$('#submitbutton').click(function () {

            var answers = new Array();
            var hiddenfields = new Array();

            var formname = "#" + $("#formname").val();

            $(':input', formname).each(function () {

                if ($(this).is(":text") || $(this).is(":radio") || $(this).is(":checkbox")) 
                {
                    var answerObject = {
                        Column_ID: $(this).attr('data-column_id'),
                        Row_ID: $(this).attr('data-row_id'),
                        Value: $(this).attr('data-theValue')
                    };

                    answers.push(answerObject);
                }

                else if($(this).is(":hidden")) {
                    var hiddenObject = 
                    {
                        Hidden_Field_ID: $(this).attr('data-hidden_field_id'),
                        Hidden_Field_Value: $(this).attr('data-hidden_field_value')
                    }

                    hiddenfields.push(hiddenObject);
                }
            });

            $('textarea', formname).each(function () {
                var answerObject = {
                    Column_ID: $(this).attr('data-column_id'),
                    Row_ID: $(this).attr('data-row_id'),
                    Value: $(this).val(),
                };

                answers.push(answerObject);
            });

            var allAnswers = {
                SessionID: 0,
                QuestionAnswerList: answers,
                HiddenAnswerList: hiddenfields
            }

            postForm(allAnswers);
        });

The Controller Action looks like this:

 [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SubmitSurvey(SurveyAnswer answers)
        {
            // Dette tillader CORS
            Response.AppendHeader("Access-Control-Allow-Origin", "*");

            bc.SaveSurvey(answers);

            return null;
        }

what am i doing wrong?

  • 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:21:28+00:00Added an answer on June 4, 2026 at 7:21 pm

    what am i doing wrong?

    You cannot expect the model binder to know that when it encounters the IQuestionAnswer interface on your SurveyAnswer view model it should use the QuestionAnswer type. It’s nice that you have declared this implementation of the interface but the model binder has no clue about it.

    So you will have to write a custom model binder for the IQuestionAnswer interface (same for the IHiddenAnswer interface) and indicate which implementation do you want to be used:

    public class QuestionAnswerModelBinder : DefaultModelBinder
    {
        protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
        {
            var type = typeof(QuestionAnswer);
            var model = Activator.CreateInstance(type);
            bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, type);
            return model;
        }
    }
    

    which will be registered in your Application_Start:

    ModelBinders.Binders.Add(typeof(IQuestionAnswer), new QuestionAnswerModelBinder());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following: <Button Content=Do XXX Height=23 Name=btnXXX IsEnabled={Binding Path=(Model:INameOfInterface.CanDoXXX)} /> <Button Content=Do
We had a View Model that looked like this: public class myViewModel { public
I'm confused - I thought I had model binding working correctly, but it was
I am wondering how to use Model Binding in a scenario where I am
I'd like to use model binding to keep my controllers looking cleaner, you can
I would like to keep model binding when doing ajax calls from my view.
I would like to create model binding functionality so a user can enter ','
I am trying to have my client side validation (model binding) to support different
I'm binding a model to my Controller and I'd like to observe any changes
The INotifyPropertyChanged is obviously very useful in the view model for data binding 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.