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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:47:46+00:00 2026-06-18T06:47:46+00:00

I have a problem with ASP.Net that is causing me to tear my hair

  • 0

I have a problem with ASP.Net that is causing me to tear my hair out. I can get parts of the model to bind using different approaches, but no one approach can bind all the data.

Controller Action signature

// Post: Profile/{customerId}/SetKnockOutQuestions/{profileId}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SetKnockOutQuestions(Int32 customerId,
    Int32 profileId,
    Int32 parentProfileId,
    IEnumerable<ProfileKnockOutQuestionModel> questions)
{

The relevant data members of the ProfileKnockOutQuestionModel class

public sealed class ProfileKnockOutQuestionModel {

    /// <summary>
    /// Parameterless constructor is required for auto-passing GET/POST data to controller actions.
    /// </summary>
    public ProfileKnockOutQuestionModel() { }


    [Required]
    [DisplayName("Lead Type Id")]
    public Int32 AdminLeadType { get; set; }

    //[Required]
    //[DisplayName("Question Type")]
    [UIHint("GridForeignKey")]
    public Int16 QuestionTypeId { get; set; }

    [Required]
    [DisplayName("Question Text")]
    public String QuestionText { get; set; }

    [Required]
    [DisplayName("Pass Answer")]
    public String Answer1Text { get; set; }

    [Required]
    [DisplayName("Fail Answer")]
    public String Answer2Text { get; set; }

    [Required]
    [DisplayName("Price")]
    [DataType(DataType.Currency)]
    [Range(0, Int16.MaxValue)]
    public Decimal Price { get; set; }

    public Int32 ProfileKnockOutQuestionId { get; private set; }

    public Int32 ProfileId { get; private set; }

    public Int32 ParentProfileId { get; private set; }

    public Int32 CustomerId { get; private set; }

    public Int32 AdminKnockOutQuestionId { get; private set; }

Attempting to send data in JSON encoded, javascript code

$.ajax({
    url: "/mvc/Profiles/78219/SetKnockOutQuestions/1605111",
    data: JSON.stringify({ questions: data,
        parentProfileId : 1605105 
    }),
    type: "POST",
    contentType: "application/json; charset=utf-8"
});

Sends this data (trimmed for brevity)

{
"questions":[
   {
     "AdminKnockOutQuestionId":8,
     "AdminLeadType":4,
     "Answer1Text":"Ya really!",
     "Answer2Text":"no wai",
     "CustomerId":78219,
     "ParentProfileId":1605105,
     "Price":2,
     "ProfileId":1605111,
     "ProfileKnockOutQuestionId":0,
     "QuestionText":"Really? Auto",
     "QuestionTypeId":0
   },

But once we’re in the action, the model binder has only bound the strings, the price and AdminLeadType. The rest of the data is all zeros. I tried adding the [Required] and [DisplayName("")] attributes to the rest of the numeric fields after noticing that all the correctly parsed fields had them and nothing changed.

The other way I have tried to send it in is as a regular form encoded post.

AXAJ javscript

$.ajax({
    url: "/mvc/Profiles/78219/SetKnockOutQuestions/1605111",
    data: { questions: data,
        parentProfileId : 1605105 
    },
    type: "POST",
});

Which results in a post body like the following (copy/pasted from Chrome’s network inspector; I could post the un-parsed, url encoded version, but instead just trust me that the ampersands and such are all in order):

questions[0][AdminKnockOutQuestionId] = 8
questions[0][AdminLeadType] = 4
questions[0][Answer1Text] = Ya really!
questions[0][Answer2Text] = no wai
questions[0][CustomerId] = 78219
questions[0][ParentProfileId] = 1605105
questions[0][Price] = 2
questions[0][ProfileId] = 1605111
questions[0][ProfileKnockOutQuestionId] = 0
questions[0][QuestionText] = Really? Auto
questions[0][QuestionTypeId] = 0

This has the opposite problem. Nothing is bound at all because the model state freaks out and says all the String Values are missing, even though I can clearly see them in the VS debugger view of the Request object.

What in the world am I doing wrong with my model binding?

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

    Your properties have private setters. You cannot possibly expect the model binder to be able to bind them. So add public setters:

    public sealed class ProfileKnockOutQuestionModel 
    {
        /// <summary>
        /// Parameterless constructor is required for auto-passing GET/POST data to controller actions.
        /// </summary>
        public ProfileKnockOutQuestionModel() { }
    
        [Required]
        [DisplayName("Lead Type Id")]
        public Int32 AdminLeadType { get; set; }
    
        //[Required]
        //[DisplayName("Question Type")]
        [UIHint("GridForeignKey")]
        public Int16 QuestionTypeId { get; set; }
    
        [Required]
        [DisplayName("Question Text")]
        public String QuestionText { get; set; }
    
        [Required]
        [DisplayName("Pass Answer")]
        public String Answer1Text { get; set; }
    
        [Required]
        [DisplayName("Fail Answer")]
        public String Answer2Text { get; set; }
    
        [Required]
        [DisplayName("Price")]
        [DataType(DataType.Currency)]
        [Range(0, Int16.MaxValue)]
        public Decimal Price { get; set; }
    
        /// <summary>
        /// Public setters are required for passing GET/POST data to controller actions.
        /// </summary>
        public Int32 ProfileKnockOutQuestionId { get; set; }
    
        /// <summary>
        /// Public setters are required for passing GET/POST data to controller actions.
        /// </summary>
        public Int32 ProfileId { get; set; }
    
        /// <summary>
        /// Public setters are required for passing GET/POST data to controller actions.
        /// </summary>
        public Int32 ParentProfileId { get; set; }
    
        /// <summary>
        /// Public setters are required for passing GET/POST data to controller actions.
        /// </summary>
        public Int32 CustomerId { get; set; }
    
        /// <summary>
        /// Public setters are required for passing GET/POST data to controller actions.
        /// </summary>
        public Int32 AdminKnockOutQuestionId { get; set; }
    
        ...
    }
    

    Once all your properties that you want to be bound have public setters your AJAX request seems fine:

    $.ajax({
        url: "/mvc/Profiles/78219/SetKnockOutQuestions/1605111",
        data: JSON.stringify({ 
            questions: data,
            parentProfileId : 1605105 
        }),
        type: "POST",
        contentType: "application/json; charset=utf-8"
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the problem is that I do have an ASP.NET TextBox in a FormView with
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem with a model in a asp.net mvc3 application. First of
I'm using asp.net mvc 3 with unobtrusive jquery validation. I have a form that
I have a asp.net app and I have a few tasks that get called
I have an ASP.NET website that seems to be using a lot of memory.
I have an ASP.NET / C# web application that is using a lot of
Update: Question updated after figuring out what was causing the ASP.NET/Razor errors. I have
I am new to asp.net mvc and i have problems that i think i
I have this problem in my ASP.NET application where I'm seeing some of my

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.