Hello, I am trying to Pass a Dropdown item from View to Controller and return value to a textbox. I have this
//Dropdown value.. when an item is selected it goes to the controller to get the value and display it on a textbox
//My Json code from Controller
public JsonResult GetAmountFromItem(int ItemId)
{
var ac = (from c in cdc.Stock
where c.ID == ItemId
select c).FirstOrDefault();
return Json(ac);
}
//I want the value to be displayed on this textbox
Thank you for your precious time ... I trully appreciate..
Vishal YelvePosted Mar 20, 2023, 2:06 PM
Hi, Try this
Tuhin PaulPosted Mar 21, 2023, 1:39 AM
Few changes I have done on the accepted answer and here is my version:
I have changed the AJAX method from $.ajax to the shorthand method $.get, which simplifies the syntax. Also I have removed the async: true option, since it's the default behavior for AJAX requests in jQuery. Removed the contentType option, since it's not necessary for a GET request.
Naimish MakwanaPosted Mar 20, 2023, 3:26 PM
Hi, Please try below
Modify your controller action
GetAmountFromItemThanks