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

  • Home
  • SEARCH
  • 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 5977611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:23:45+00:00 2026-05-22T21:23:45+00:00

I want my model’s part to be accessible to my page’s JavaScript, so I

  • 0

I want my model’s part to be accessible to my page’s JavaScript, so I include the following script tag into the model:

<script type="text/javascript">
var filter = @Html.Raw(@Json.Encode(Model.Filter));
</script>

The filter object is a filter for the subsequent queries, which are done via AJAX:

<script type="text/javascript">
function DownloadData() {
    $.ajax({
        url: '@Url.Action("GetData")',
        type: "POST",
        data: filter,
        success: function (data) {
        }
    });
}
</script>

It all works OK, but for one part: the filter‘s string properties are not null, but "null". I don’t touch the filter variable in my JavaScript yet

Model:

public class SellOffersFilter
{
    public int MinAge { get; set; }
    public string Country { get; set; }
    public string City { get; set; }
}

Controller:

public ActionResult SellOffersGetPage(SellOffersFilter filter)
{
    //here both filter.Country and filter.City are equal to "null"
}

The POST form looks like MinAge=0&Country=null&City=null, and JavaScript debugger shows that filter.Country is equal to null, not the "null" string.

Is there a way to force jQuery not to pack the filter’s fields into the POST request, if they are null? Or another easy way to pass null values through jQuery.ajax()?

  • 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-22T21:23:46+00:00Added an answer on May 22, 2026 at 9:23 pm

    I didn’t figure out the answer, so I had to manually replace null values with empty strings on the server.

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

Sidebar

Related Questions

I want to return the Model (data) of a controller in different formats (JavaScript/XML/JSON/HTML)
I want to model the following scenario in the database: I have a Package,
I want to model an article with revisions in Django: I have following in
I want to pass the mvc page model back to my controller within a
I want to model the following situation. I have a table of items, and
I want to model a heart shape in 3D with as little code needed
I want to model messages between users, here is the requirement: User has received
I'm using jquery for modal dialogs. I want to open model dialog from one
I want to have a model with calculated fields that I can apply sorting
I want to send ViewData.model to Special action with the last user data entry.

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.