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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:41:58+00:00 2026-05-30T00:41:58+00:00

I am using MVC3 and that i know MVC3 support binding JSON literal to

  • 0

I am using MVC3 and that i know MVC3 support binding JSON literal to Action parameter. But i can’t do it successfully;

I have a class name Tag

public class Tag
{
    public int tagId { get; set; }
    public string tagName { get; set; }
}

An Action on controller called Tag

    [HttpPost]
    public ActionResult Tag(Tag tag)
    {
        // Here will be codes...
        return Json(new { success = 0 });
    }

Javascript code that send js object as JSON to my action

    var tag ={tagId:5,tagName:"hello"};
    $.ajax({
           url: "/image/tag",
           type: "POST",
           data: $.toJSON(tag),
           success: function (r) {
               if (r.success == 1) {
                   window.location = r.redirect;
               }
           }

Post Data that I see in Firebug Net tab

{"tagId":5,"tagName":"hello"}

Parameter name tag in Tag Action is not null but has values O for tagId and null for tagName.
What the problem in here?

  • 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-30T00:42:00+00:00Added an answer on May 30, 2026 at 12:42 am

    You need to set the content type of the request to application/json:

    $.ajax({
        url: '/image/tag',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: $.toJSON(tag),
        success: function (r) {
            if (r.success == 1) {
                window.location.href = r.redirect;
            }
        }
    });
    

    Ah, and you don’t need to have your Tag model properties start with a lowercase letter:

    public class Tag
    {
        public int TagId { get; set; }
        public string TagName { get; set; }
    }
    

    Remark 1: The JavaScriptSerializer class that ASP.NET MVC 3 uses behind the scenes is capable of properly handling this.

    Remark 2: In your Tag action you seem to be returning the following JSON: {"success":0} whereas in your success AJAX callback you seem to be using some r.redirect property which doesn’t exist.

    Remark 3: Avoid naming your controller actions the same way as your view models. Normally action names should represent verbs (like List, Save, Delete, …) whereas view models represent resources (TagModel, …).

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

Sidebar

Related Questions

I know that what I'm trying to do is bad idea, but I have
I have created a site using asp.net mvc3 and I have some action in
Using MVC3.NET I have a file upload method in a controller that works fine
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C#, I need a class called User that has a username, password, active
I have an ASP.NET MVC3 app that features a form with a nested-table input
I have developed a project using MVC3 and Code first Entity Framework 4.0 as
Using MVC3, I have a Student Repository (in a project) and a StudentService (in
I am using MVC3 and added model validation with required attributes. Then I have
I have been reading articles about asynchronous messaging between clients using MVC3 and the

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.