Tips for transferring JavaScript data to an ASP.NET MVC controller

This is my controller:

public ActionResult GetFilterUsers(int pageNumber)
{

    //......

}

This is my js code:

$('#users-data-table').DataTable({
            serverSide: true,
            ajax: {
                url: "@(Url.Action("GetFilterUsers", "Users", new { area = "Admin" }))/" + table.page.info().page, 
                type: "GET"
            }
        });

this specific URL string isn't functioning correctly

url: "@(Url.Action("GetFilterUsers", "Users", new { area = "Admin" }))/" + table.page.info().page, 

Could someone advise me on how to successfully pass table.page.info().page to my controller?

Answer №1

Update the URL to:

url: '@(Url.Action("GetFilterUsers", "Users", new { area = "Admin" })) + "?pageNumber=" + table.page.info()

Now the URL will include pageNumber as a query string parameter. If you prefer to use this URL format:

url: "@(Url.Action("GetFilterUsers", "Users", new { area = "Admin" }))/page/" + table.page.info().page
, make sure to define and register the appropriate route and action.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The event handling functionality for CheckBox1 in ASP is malfunctioning

I am looking for a way to show an HTML table (id='xx') when a user clicks on a checkbox in an ASP page. Additionally, I want the table to become invisible again once the user unchecks the checkbox. <table> <tr> <td co ...

Retrieving a specific variable from a cookie value that is stored within a JSON array

Is there a way to pass a single variable from a JSON array stored in the qookie file value to JavaScript? The qookie code looks like this: <?php $cookie_key = 'count'; CookieManager::store($cookie_key, json_encode(array( 'SameSite&ap ...

Guide to fetching and displaying a complex array API using JavaScript's fetch method

Recently, I've been delving into the world of APIs and making sure I call them correctly. Using the fetch method has been my go-to so far, and here's a snippet of the code where I reference an API: fetch('https://datausa.io/api/data?d ...

What causes certain webpack / Babel ES6 imports without a specified extension to resolve as "undefined"?

When I try to import certain ES6 files (such as .js, .jsx, .ts, .tsx) using the syntax import ComponentName from './folder/ComponentName'; (without extension), they end up resolving as undefined. This occurs even though there are no errors from W ...

The Google Apps mail server operates smoothly when handling less than 50 messages, but encounters issues when sending a larger quantity

My asp.net (mvc2) web app webinar registration system is currently set up to send emails containing connection information to attendees. Right now, we simply iterate through the list of attendees and use System.Net.Mail.SendMail for each one. These emails ...

JavaScript Object-Oriented Programming - Accessor method that retrieves a property from the parent

Having trouble with implementing getters and setters for model objects in Angular. Facing an error: TypeError: Cannot read property 'firstName' of undefined at User.firstName (http://run.plnkr.co/AvdF2lngjKB76oUe/app.js:35:32) The code snippet: ...

When uploading a file through a C# API, an HTTP response of "Unsupported Media Type" is

I am currently utilizing the oi.file.js directive from https://github.com/tamtakoe/oi.file in conjunction with Angular. This is how my HTML structure looks: <form name="EditOrder" enctype="multipart/form-data"> <input type="file" oi-file="opti ...

Storing the model using three.js

Is it feasible to store models created in three.js into a database and later retrieve them, rather than just using the save tab? ...

Incorporate JSON information into HTML dropdown menu using Google API

I'm finding it difficult with this task. Below is a list that needs the name and address inserted into the dropdown menu from the JSON file. <div class="dropdown-list"> <div class="list-container"> <ul class="list" ...

Leverage the power of React in tandem with Express

My web site is being created using the Express framework on NodeJS (hosted on Heroku) and I'm utilizing the React framework to build my components. In my project, I have multiple HTML files containing div elements along with React components that can ...

How can we verify the validity of URLs based on their length, presence of capital letters, and specific whole words?

I'm currently working on a piece of code that verifies the URL provided by users during sign-up for my application. I want to implement the following restrictions: URL must be at least 3 characters long No capital letters allowed Avoid certain words ...

After installing grunt, the Gruntfile cannot be located. How can this issue be resolved?

After installing grunt, I encountered a problem. Despite trying some commands suggested on stackoverflow in this How to install grunt and how to build script with it, running the grunt command still shows the same result. What steps should I take next?ht ...

Step-by-step tutorial on designing an input slider to dynamically adjust the CSS :before linear-gradient values

Is there a way to achieve a gradient effect using pseudo-element :before on an image that can be customized by adjusting a slider input? I've been trying to implement this feature with the following code, but have not been successful so far. var ...

Selenium WebDriver producing unexpected results with getTitle() method

Currently, I am executing an automated test script in a selenium-webdriver environment using Phantomjs. My approach involves running the script through node.js, rather than utilizing Python or C#. The steps I took to set up the environment are outlined b ...

error encountered when working with date arrays in JavaScript

I find myself perplexed by this particular issue. Although the following code snippet appears to function correctly, it exhibits some peculiar behavior. var tmpcurdte = eval(dataSource[i].startDate); tmpcurdte.setDate(tmpcurdte.getDate() + 1); while (tm ...

Using a controller variable inside an AngularJS directive requires proper binding and referencing within the

Can someone help me with using a controller variable inside a directive? I have tried using popoverHtml inside the scope in the directive but it seems that when I add a type like this, it does not work: For example: scope: { popoverHtml:'@', typ ...

The select menu default value is not displaying properly after the update to select2 version 4.0.3

After updating the select2 package from version v4.0.0 to v4.0.4, I noticed that the default value of the select menu was no longer appearing as expected: https://i.sstatic.net/UO3yZ.jpg For those interested, here is a link to my code on JSBin: view jsbi ...

Unable to access Form element in Firefox browser

I'm struggling with debugging unfamiliar problems. For instance, in my HTML there's a form: <form name="myForm" > <table> <tr> <td> <input type="radio" name="myType" value="val" onclick="someF ...

a guide on displaying information through JSON

HOW TO SOLVE the error in Unity 3D Json Exception: Input is not valid JSON text LitJson.JsonReader.Read () I am working on developing a quiz game that displays questions and answers on buttons. How can I fix this issue to ensure the ...

modifying the appearance of the play button through a JavaScript event without directly altering it

I am currently working on building a music player from scratch using HTML, CSS, and JavaScript only. To store the list of songs, I have created an array named "songs" with details such as song name, file path, and cover image path. let songs = [ {songNa ...