I have a cshtml file with a form:
<div class="widget-content widget-content-area">
<form id="ticketdata" action="/Ticket/[email protected]" method="post">
<input type="hidden" asp-for="@Model.TicketId" />
...
...
...
<button id="btnticket" type="submit" class="btn btn-primary" onclick="CreateTicket(">Create Ticket</button>
</form>
In the first field I am selecting a Name from a drop down menu who has a unique userId. Based on the UserId I am fetching other details as well(and that’s working).
Here is the script for that:
$("#CustomerName").change(function () {
var CustomerName = $("#CustomerName").val();
$.ajax({
url: "../Ticket/FetchCustomerAddress",
data: { userId: CustomerName },
type: "Get",
success: function (data) {
$('#Address').val(data.address);
$('#City').val(data.city);
$('#ZipCode').val(data.zipCode);
$('#CustomerName').val(data.customerId)
}
After filling the form, at the time of submission. I want that userId for further operations. But I am not getting those details. I am only getting other details in the form and not the selected userId.
In the Ticket model, I have a parameter userId.
How to get that userId in the controller? using jquery or javascript?