What i want is my controller action method should fire thrugh javascript function on input type submit button click event and bind textbox with new values.
// My Controller
[HttpPost]
public ActionResult GetSalary(FormCollection formCode)
{
// Getting form values from view
string salCode = formCode["vc_Salary_Code"].ToString();
string empId = formCode["vc_Employee_ID"].ToString();
// execute query and get data from database
var salPosList = sdm.accountSalaryMaster.SqlQuery("query").ToList();
// Some Calculations and assign values to the variable
Object[] salaryTypes = new Object[] { amtAllowance, amtBack, amtEmi, amtOvertime, amtLeave, amtDeduction, totalAdd, totalSub, netSalary };
return Json(salaryTypes, JsonRequestBehavior.AllowGet);
}
<script>
function GetSalary() {
var id = $('#EmployeeID').val();
var cod = $('#SelectSalaryCode').val();
$.ajax({
url: '/Account/GetSalaryDetails',
type: "GET",
dataType: "JSON",
data: { empId: id, salCode: cod },
success: function (salaryTypes) {
$('#dc_Salary_Allowances').val(salaryTypes.amtAllowance),
$('#dc_Back_Due').val(salaryTypes.amtBack)
}
});
}
</script>
// My View
@using (Html.BeginForm("SalaryPayment", "Account", FormMethod.Post))
{
@Html.Editor("vc_Employee_ID", new { htmlAttributes = new { @class = "form-control", @id = "EmployeeID", @placeholder = "Employee ID..." } })
@Html.DropDownList("vc_Salary_Code", null, "Select Salary Code...", new { @class = "form-control", @id = "SelectSalaryCode" })
<input type="submit" class="btn btn-sm btn-success" onclick="GetSalary();" value="Get" style="width:70px" />
@Html.Editor("dc_Salary_Allowances", new { htmlAttributes = new { @class = "form-control", @id = "SalaryAllowances", @placeholder = "Allowances..." } })
@Html.Editor("dc_Back_Due", new { htmlAttributes = new { @class = "form-control", @id = "BackDue", @placeholder = "Back Due..." } })
}