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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:55:06+00:00 2026-05-30T03:55:06+00:00

I’m pulling my hair out on this one. I am trying to implement a

  • 0

I’m pulling my hair out on this one.

I am trying to implement a multi-step wizard, and i’m using the Html.Serialize html helper in MVC3 Futures. This works well, except one of the properties in my model is a SelectList. I don’t want this property serialized (and it blows up when it tries anyways).

I can’t use [NonSerialized] because that only works on fields, not properties. I’ve even tried some of the other normal ways such as [XmlIgnore] (which I didn’t think would work anyways).

Can anyone suggest an attribute that will ignore a property in a model when using Html.Serialize?

EDIT:

The error I get when I try to serialize is a InvalidDataContractException. There is this message:

Type ‘System.Web.Mvc.SelectList’ cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

However, if I do this then I have to mark all the members with [DataMember] just to exclude 1 property, which seems kind of stupid.

UPDATE:

A quick example of this is this bit of code (make sure to add reference to System.Runtime.Serialization.dll):

Test.cs

[Serializable]
public class Test
{
    public int ID { get; set; }
    [IgnoreDataMember]
    public SelectList TestList { get; set; }
}

HomeController.cs

public ActionResult About()
{
    return View(new Test() { ID = 0, TestList = new SelectList(new [] {""})});
}

Home/About.cshtml

@using Microsoft.Web.Mvc
@model MvcApplication3.Models.Test 

@Html.Serialize("Test", Model)

This generates the InvalidDataContractException

  • 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-30T03:55:07+00:00Added an answer on May 30, 2026 at 3:55 am
    public class MyViewModel
    {
        [IgnoreDataMember]
        public SelectList Items { get; set; }
    
        ...
    }
    

    or simply:

    public class MyViewModel
    {
        public IEnumerable<SelectListItem> Items { get; set; }
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.