locked
How can send the value from html textbox into controller action RRS feed

  • Question

  • User-1355965324 posted

    I want to send the value of Depot Number into the controller action SearchCustomer

    My code is given below

    In Html
    <div class="col-sm-3">
    <select id="dropdownDepot" class="form-control" asp-for="DepotNo" asp-items="@ViewBag.UserDepots"
    data-role="select" onchange="FillEmployeeDropdown()"></select>
    <span asp-validation-for="DepotNo" class="text-danger"></span>
    </div>
    <div class="input-group"> <input type="text" class="form-control" asp-for="CustomerCode" id="txtCustomer" placeholder="Search" /> <span class="input-group-addon"> <i class="fa fa-search" onclick="ShowCustomerSearch()"></i> </span> </div>

    In Javascript

    function ShowCustomerSearch() {
            var url = "/Employee/SearchCustomer"; // I want to pass the value of DepotNo into the action Searchcustomer
            $("#CustomerSearchDiv").load(url, function () {
                $("#CustomerSearchModal").modal("show");
            })
        }

    In Controller

    public IActionResult SearchCustomer(string Depotno) // Receive the value of depot number from html 
            {
                CustomerModel Customer = new CustomerModel();
                ViewBag.Customers = EmployeeService.GetCameoCustomerMTS(connectionSettings);
                return PartialView("CustomerSearch");
    
            }
    

    Please help

    Tuesday, September 10, 2019 3:51 PM

Answers

  • User2053451246 posted
    var url = "/Employee/SearchCustomer?Depotno=" + $("#DepotNo").val();

    Look at the HTML of your rendered page to verify the actual id the DepotNo textbox is assigned and change #DepotNo as necessary.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 10, 2019 7:31 PM

All replies

  • User2053451246 posted
    var url = "/Employee/SearchCustomer?Depotno=" + $("#DepotNo").val();

    Look at the HTML of your rendered page to verify the actual id the DepotNo textbox is assigned and change #DepotNo as necessary.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 10, 2019 7:31 PM
  • User1634355159 posted

    Hi polachan,

    You could add values to the url that need to be passed to the background. Your “Depotno” is going to get the selected items in the select tag, so you could write like this:

    var depotno = $("#dropdownDepot option:selected").val();
    
    var url = "/Employee/SearchCustomer?Depotno=" + depotno;

    Best Regards ,

    Lewis Lu

    Wednesday, September 11, 2019 4:21 AM