Value not being passed to action during AJAX call

I have a View that includes:

(...)

<div id="txtMan@(item.ManufacturerId)" hidden>
    @Html.TextBoxFor(modelItem => item.ManufacturerName, new { @id = "txtBoxMan"+item.ManufacturerId })
</div>
<td>
    <input class="btnSave" id="btnSave@(item.ManufacturerId)" type="button" value="Save" onclick="saveButtonPressed(@item.ManufacturerId);" hidden />
</td>

(...)

The accompanying JavaScript function:

saveButtonPressed = function (id) {
    var newManName = $('#txtMan' + id).val();

    $.ajax({
        type: "POST",
        async: true,
        url: '/Admin/BrandConfigurationNameUpdate/' + newManName,
        dataType: "json",
        success: function () {
            alert('Added');
        }
    });
}

And the Controller method:

public static void BrandConfigurationNameUpdate(string id)
{ 

}

My goal is to store the text box input in the database. However, when I put a breakpoint in my Controller, it never gets hit. Any suggestions?

UPDATE: I attempted using GetJSON, but it still doesn't work. Here's the code snippet:

saveButtonPressed = function (id) {
    var newManName = $('#txtBoxMan' + id).val();
    alert(newManName);
    var URL = "~/Areas/Admin/Controller/Admin/BrandConfigurationNameUpdate/";

    $.getJSON(URL, { "id": id, "newManName": newManName }, function (data) {
        alert("finished");
    });
}

Answer №1

Make sure to include a data option with key-value pairs in order for the value to be successfully POSTed:

saveButtonPressed = function (id) {
    var newManName = $('#txtMan' + id).val();

    $.ajax({
        type: "POST",
        async: true,
        url: '/AdminController/BrandConfigurationNameUpdate/',
        data : {newManName : newManName},
        dataType: "json",
        success: function () {
            alert('Added');
        }
    });
}

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

When the size is adjusted, seamlessly swap out the current image for a new one without the need to refresh the page

I am currently in the process of developing a website. As part of this project, I am utilizing a bootstrap carousel to display images dynamically based on the screen orientation. Using JavaScript, I am capturing the width and height of the screen and sen ...

Encountering an issue while attempting to locate an already existing product in the localStorage using JavaScript

I'm currently working on incorporating a cart system using localStorage and have provided the codes below. Can someone help me understand how to accomplish this? const data = { description: "Cum sociis natoque", mediaUrl: "/prod ...

Issues with submitting data using jQuery AJAX PUT request

I have a PHP script with the following content: if ($_SERVER['REQUEST_METHOD'] === 'PUT') { echo '{ "response": "' . $_REQUEST['id'] . '" }'; } Now, I am trying to use jQuery to make an AJAX request t ...

Navigate to a different position of a specified element within an expanding pivot grid

I'm currently dealing with a pivot table/grid that allows users to expand and collapse rows. My challenge is figuring out how to scroll to an expanded row after an expansion occurs. Typically, I use the following code for scrolling functions: ...

Breaking or wrapping lines in Visual Studio Code

While working in Visual Studio Code, I often encounter the issue of long lines extending beyond the screen edge instead of breaking and wrapping to the next line. This lack of text wrapping can be quite bothersome. I utilize a split-screen setup on my co ...

What is the best way to establish a global database connection in express 4 router using express.Router()?

Is there a way to pass a global variable in Node.js from a file to a module? I have been attempting to do so with a 'db' variable that represents a MongoDB connection. I tried copying the content of my file for the connections, but it didn't ...

Can you explain the distinction between the onclick(function(){}) and on('click',function(){}) functions in jQuery?

My goal is to dynamically load pages into a specific div using ajax. Here's my HTML code: <ul id="nav" class="nav" style="font-size:12px;"> <li><a href="#" id="m_blink">Tab1</a></li> <li><a href="#" id= ...

Issue with AnimeJS Motion Path causing element to deviate from desired SVG path

I'm attempting to use an SVG element and the AnimeJS library to make the orange marker follow the course of this RC car race track. https://i.stack.imgur.com/8FKHC.png Despite my efforts, I am encountering strange and undesirable outcomes. At times ...

Tips for modifying the text of a label within a node package module

I'm in the process of developing a React web application, and I've incorporated an English node module package called react-timelines. However, I need to translate the label text "Today" into Spanish, which should be "Hoy". When I attempt to modi ...

Insert the entered value into the table

I'm struggling to extract the content from an input textfield and insert the value into a table row. However, every time someone submits something, the oldest post shifts down by one row. Below is my current attempt, but I'm feeling quite lost at ...

Steps for displaying a division on clicking a hyperlink

I am currently working on my main menu layout in HTML, and here is the code snippet: <div id="main-container"> <div id="main-wrapper"> <div id="logo"> <h1 id="title">port ...

Using PHP to create an HTML text box that calculates the total amount by multiplying the quantity with the

$res=mysql_query($qry); while($row= mysql_fetch_array($res)) { echo "<tr><td>".$row['Food_Name']."</td> <td>".$row['Price']."</td> <td><input type='text' name='qty". $row['code& ...

Utilizing array iteration to display images

I am having trouble getting the images to display on my card component. The description appears fine, but the images are not rendering properly even though I have the image data in an array. Here is the Card Component code: export const Card = (props) =&g ...

I am unsure how this type of jQuery AJAX data : () will be interpreted

I'm not a beginner nor an expert in jQuery. I'm modifying a jQuery code for opencard checkout section. There is a Javascript file in this section that sends data to the server. I came across an AJAX request with data structured like this: url: ...

How can I retrieve the total number of records (count) in an XML response using PostMan?

Hello, I'm currently attempting to determine the length of an XML response but I'm running into some issues. The error message I am encountering is as follows: "There was an error in evaluating the test script: ReferenceError: xml2json is not def ...

The Disable Button is malfunctioning as the text is deleted but the button remains enabled

One issue I am facing is that even after removing the numbers from the textboxes, the submit button remains enabled. Initially, when I enter inputs in the textbox, it enables the button, but even after removing a number, the button stays enabled. This is ...

Using ng-value does not trigger any updates to the Ng-model

After setting the input value Array property sum, it displays the value in the input field. However, when submitting the form, the Quantity property is not being received in the Order object. I noticed that if I change the value manually, then the Quanti ...

"Exploring the power of Selenium with Chromedriver integration in a

Attempting to run integration tests using javascript for my application (Chrome being the browser of choice), I encountered an issue where Capybara failed to detect the Selenium driver. The testing environment consists of: Linux (Ubuntu 12.10) RoR 3.1 Rsp ...

Submit data via POST method on the modified URL

I need assistance with modifying the data of a URL and making a POST request to it. The URL in question is as follows: http://domanin.com/search-result/?start=06%2F08%2F2017&end=06%2F09%2F2017&room_num_search=1&adult_number=1&children_num= ...

"Troubleshooting the Undefined Object Dilemma

I previously asked a similar question, but I have since made some progress. Currently, I have two JavaScript files for a menu bar and an additional two for another object on the page. This is my code that is currently causing an issue: <html xmlns="h ...