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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:29:25+00:00 2026-06-13T14:29:25+00:00

I am trying to post some data to my MVC 3 controller through a

  • 0

I am trying to post some data to my MVC 3 controller through a hidden text field that contains some JSON. I have that JSON passed in via string coursesList. Anyone have an idea why this is not working?

All I’m doing is making a byte [] out of the JSON string, writing it to a MemoryStream, and deserializing that stream — or, attempting to. BookCourse bc always ends up with null properties.

Here’s something like the JSON I would be using:

[{"coursesection":"1234","netlogon":"jsmith","label":"CRSE-1313 Generic Course Titling ~ Joe Smith"}]

And here’s the object to be deserialized into:

using System.Runtime.Serialization;

namespace xxxx.Models
{
    [DataContract]
    public class BookCourse
    {
        [DataMember]
        public string coursesection { get; set; }

        [DataMember]
        public string netlogon { get; set; }

        [DataMember]
        public string label { get; set; }
    }
}

Finally, the controller action code to do it —

var byteArray = Encoding.ASCII.GetBytes(coursesList);

// Deserialize byte array to data type
var stream = new MemoryStream();
stream.Write(byteArray, 0, byteArray.Length);
var crs = new DataContractJsonSerializer(typeof(BookCourse));
stream.Position = 0;

// Read stream to object
ad.CourseSectionIDs = new List<int>();
try
{
    var bc = (BookCourse) crs.ReadObject(stream);
    while (bc.coursesection != null)
    {
        cs.AssociateCourseBook(bc.netlogon, bc.coursesection, ad.ISBN);
        bc = (BookCourse)crs.ReadObject(stream);
    }
}
catch (System.Runtime.Serialization.SerializationException e)
{
    // Is this best practice for handling "none"?
}
  • 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-13T14:29:26+00:00Added an answer on June 13, 2026 at 2:29 pm

    Your JSON string represents a collection of BookCourse, not a single BookCourse. So adapt your code:

    var serializer = new DataContractJsonSerializer(typeof(BookCourse[]));
    

    and then:

    var bookCourses = (BookCourse[])crs.ReadObject(stream);
    

    or if you want to work with a single BookCourse you will need to change your JSON string and remove the wrapping square brackets which represent a collection.

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

Sidebar

Related Questions

I am trying to post some data to a ASP.NET MVC Controller Action. Current
Trying to post JSON data to Spring controller.. Not working at all JSP Code:
I have an ASP.Net MVC application. I am trying to post data to an
I am trying to post some data from one local asp.net mvc site to
I am trying to post back some data using a viewmodel i have created
I'm trying to post some array of data to controller.. My view is like:
I'm trying to create an MVC view that will display some data in a
I'm trying to post some data to a function that will do a mysql
I Have a hidden field that contains a value and my code block within
I'm trying to POST some JSON data using Adobe Flex but having some problems.

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.