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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:06:37+00:00 2026-06-05T11:06:37+00:00

Consider the following model which uses XmlSerializer and JSON.net to serialize the object to

  • 0

Consider the following model which uses XmlSerializer and JSON.net to serialize the object to and from the respective formats.

[XmlRoot("my_model")]
[JsonObject("my_model")]
public class MyModel {

    [JsonProperty("property1")]
    [XmlElement("property1")]
    public string Property1 { get; set; }

    [JsonProperty("important")]
    [XmlElement("important")]
    public string IsReallyImportant { get; set; }
}

Now consider the following ASP.NET MVC 3 action that accept JSON or XML requests and returns model in the respective format (based on the accept header).

public class MyController {
    public ActionResult Post(MyModel model) {

        // process model

        string acceptType = Request.AcceptTypes[0];
        int index = acceptType.IndexOf(';');
        if (index > 0)
        {
            acceptType = item.Substring(0, index);
        }

        switch(acceptType) {
            case "application/xml":
            case "text/xml":
                return new XmlResult(model);

            case "application/json":
                return new JsonNetResult(model);

            default:
                return View();
        }
    }
}

Custom ValueProviderFactory implementations exist for JSON and XML inputs. As it stands the IsReallyImportant is being ignored when the input is being mapped to MyModel. However, if I define the attributes of IsReallyImportant to use “isreallyimportant”, then information is correctly serialized.

[JsonProperty("isreallyimportant")]
[XmlElement("isreallyimportant")]
public string IsReallyImportant { get; set; }

As expected the default binder uses the property name when mapping incoming values to the model. I had a look at the BindAttribute, however its not supported on properties.

How does one tell ASP.NET MVC 3 that the property IsReallyImportant should be bound to “important” in the incoming request?

I have too many models to write a custom binder for each. Note that I don’t use ASP.NET Web API.

  • 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-05T11:06:39+00:00Added an answer on June 5, 2026 at 11:06 am

    You can do only one custom ModelBinder which will look for JSonProperty and XMLElement attributes to map the right properties. This way you could use it everywhere and you won’t have to develop a modelbinder for each model. Unfortunately, there is no other option to modify the property bindings than custom modelbinders.

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

Sidebar

Related Questions

Consider the Following object model (->> indicates collection): Customer->Orders Orders->>OrderLineItems->Product{Price} The app is focused
Consider the following django model from django.db import models from django.contrib import auth class
Consider a typical social networking website, which has more or less the following models:
Consider the following Django models: class Host(models.Model): # This is the hostname only name
Consider the following data model: Suppose I have a table called SuperAwesomeData where each
Consider I have defined the following models: class Tag(models.Model): name = models.CharField(max_length=20) class Entry(models.Model):
Consider the following R code (which, I think, eventually calls some Fortran): X <-
consider the following model: class Tweet(db.Model): text = db.StringProperty created_at = db.DateTimeProperty() class Company(db.Model):
Consider following: Partial View: <%= Html.ListBox(BlackList, Model.Select( x => new SelectListItem { Text =
Consider the following model: public class BandProfileModel { public BandModel Band { get; set;

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.