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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:47:13+00:00 2026-06-18T08:47:13+00:00

I have a problem and I don’t know what is the issue. I am

  • 0

I have a problem and I don’t know what is the issue.
I am constructing a Json object and I want to post it back with $.ajax. The problem is I always get null in my Action.
here is Ajax Part :

            $("input[type=button]#ajax-editor-save").click(function() {

            var hotelPropertyAssignModel = new Object();
            hotelPropertyAssignModel.Hotel_Id = 1;
            hotelPropertyAssignModel.HotelProperties = new Array();

            $("input.ajax-editor[data-edited=true]").each(function() {
                var hotelPropertyValue = new Object();
                hotelPropertyValue.HotelProperty_Id = $(this).attr("data-hotelPropertyId");
                hotelPropertyValue.Language = $(this).attr("data-lang");
                hotelPropertyValue.Value = $(this).attr("value");
                hotelPropertyAssignModel.HotelProperties.push(hotelPropertyValue);
            });

            $.ajax({
                url: '@Url.Action( "SetProperties" )',
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(hotelPropertyAssignModel)
            });
        });

and here is Action:

[AcceptVerbs( HttpVerbs.Post )]
[HttpPost]
public void SetProperties ( string hotelPropertyAssignModel )
{

}

I changed the parameter to string to validate how json is coming. I get null when I replace it with correct model too!
anybody can help?

  • 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-18T08:47:14+00:00Added an answer on June 18, 2026 at 8:47 am

    Make sure you set the proper contentType:

    $.ajax({
        url: '@Url.Action( "SetProperties" )',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(hotelPropertyAssignModel)
    });
    

    The dataType parameter that you were using indicates the response type, not the request type. You don’t need it if your controller action properly sets the Content-Type response header which it normally does if you are returning for example a JsonResult.

    But from what I can see your controller action is declared as void which obviously is wrong. Controller actions must return action results. If you don’t care about the content, simply use an EmptyResult:

    [AcceptVerbs( HttpVerbs.Post )]
    [HttpPost]
    public ActionResult SetProperties ( string hotelPropertyAssignModel )
    {
        ...
        return new EmptyResult();
    }
    

    Also there’s another very serious problem with your controller action. It is taking a string argument instead of a view model!!! I don’t know how you were possibly expecting to bind a JSON request to some string.

    So, immediately define a view model that will match the JSON structure you are willing to send:

    public class HotelAssignmentViewModel
    {
        public int Hotel_Id { get; set; } 
        public HotelPropertyViewModel[] HotelProperties { get; set; }
    }
    
    public class HotelPropertyViewModel
    {
        public int HotelProperty_Id { get; set; }
        public string Language { get; set; }
        public string Value  { get; set; }
    }
    

    and then have your controller action take this view model as parameter:

    [AcceptVerbs( HttpVerbs.Post )]
    [HttpPost]
    public ActionResult SetProperties ( HotelAssignmentViewModel model )
    {
        ...
        return new EmptyResult();
    }
    

    I also notice another problem with your code. You seem to have subscribed to the click event of some DOM element to trigger the AJAX request but you never cancel the default action by returning false from this event. So for example if this is a submit button or an anchor, it will simply redirect the browser away from the page leaving no time for your AJAX request to execute. So make sure you cancel this default action by returning false from your click handler:

    $("input[type=button]#ajax-editor-save").click(function() {
        ...
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem at jquery post, php get. but i don't get any value.
I have problem and don't know how to get some clues on what might
I have a problem I don't know how to solve. I have an Indy10
I have a problem which I don't really know how to solve. I have
I have a problem which I don't know how to fix. It has to
I still have the problem and i don't know how to fix it. thanks
So I have a problem that I don't really know how to go about.
I want to place UItextField in UITableViewCell but I have problem. Text field don't
I have a problem with a script and I don't know how to handle
I have a simple problem but I don't know how to solve it because

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.