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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:38:18+00:00 2026-06-01T05:38:18+00:00

In an ASP.NET MVC3 application, I’m trying to use jQuery to make an asynchronous

  • 0

In an ASP.NET MVC3 application, I’m trying to use jQuery to make an asynchronous post to an action.

The following JSON object is being passed as data…

{
    categoryId: "21"
    content: "asdf"
    reference: "asdf"
    tags: [
        {id: 1, name: "asdf", status: 1},
        {id: 2, name: "asdf", status: 1},
        {id: 3, name: "asdf", status: 1}
    ]
}

The method signature I have to receive the request is

[HttpPost]
public ActionResult Create(String reference, Int32? categoryId, String content, IEnumerable<TagDTO> tags)

with TagDTO is being defined as:

public class TagDTO
{
    public String name { get; set; }
    public Int32 id { get; set; }
    public Int32 status { get; set; }
}

I should mention that before I introduced the array of objects to the JSON object and to the signature of the action method, this was working perfectly. And the Post is still successfully reaching the action, only the data in the IEnumerable is not coming through correctly. It will give me the correct number of objects in the IEnumerable, but they are all initialized to default values. (id=0, name=null, status=0)

I’m not sure what I’m doing wrong here. I hope this makes sense. I’m hoping someone can show me the proper way to pass data to an MVC action in this manner.

Thanks


Here is the javascript function I’m using to perform my ajax call…

function saveResource() {
    var tagAssignments = [];
    for (var x = 0; x < $('.tag-assignment').length; x++) {
        var tag = $($('.tag-assignment')[x]);
        tagAssignments.push({
            name: tag.find('.tag-name').html().toString(),
            id: parseInt(tag.find('.tag-id').html()),
            status: parseInt(tag.find('.tag-status').html())
        });
    }

    $.ajax({
        url: '/Resources/Create',
        dataType: 'json',
        type: 'POST',
        success: function (data) {
            if (data.status == 'Success') {
                forwardToDefaultPage();
            } else {
                alert(data.status);
            }
        },
        data: {
            reference: $('#txt-resource-reference').val(),
            categoryId: $('#ddl-category').val(),
            content: $('#txt-resource-content').val(),
            tags: tagAssignments
        }
    });
}
  • 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-01T05:38:20+00:00Added an answer on June 1, 2026 at 5:38 am

    I’d would recommend you using view models and send JSON request.

    So a view model:

    public class CreateViewModel
    {
        public string Reference { get; set; }
        public int? CategoryId { get; set; }
        public string Content { get; set; }
        public IEnumerable<TagDTO> Tags { get; set; }
    }
    

    action:

    [HttpPost]
    public ActionResult Create(CreateViewModel model)
    {
        ...
    }
    

    AJAX request:

    // TODO: build this object dynamically as you are currently doing
    // but always start with hardcoded values like this to test first
    var data = {
        categoryId: '21',
        content: 'asdf',
        reference: 'asdf',
        tags: [
            { id: 1, name: 'asdf', status: 1 },
            { id: 2, name: 'asdf', status: 1 },
            { id: 3, name: 'asdf', status: 1 }
        ]
    };
    
    $.ajax({
        url: '@Url.Action("create", "resources")',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({ model: data }),
        success: function(result) {
            ...
        }
    });
    

    The JSON.stringify method used here is built into modern browsers. If you need to support legacy browsers you could add the json2.js script to your page.

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

Sidebar

Related Questions

In my ASP.NET MVC3 application I have the following method that use EF entities
I'm about to create an ASP.net MVC3 application where I need to make a
I am trying to build set of reusable components for the ASP.Net MVC3 application.
This is about asp.net mvc3 web application. We have used Object cache to store
I am building an asp.net mvc3 application and I have decided to use areas
I am working on a asp.net mvc3 application. I have this Jquery function function
I'm following along the ASP.Net MVC3 application Music Store and I've noticed this. Here
I have the following WebGrid in my ASP.NET MVC3 test application. It displays a
I have a ASP.NET MVC3 application, which uses JSON to comunicate with a Flash
I am trying deploy my asp.net mvc3 application, here it is what i done

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.