可以使用URL拼接方式方法传参
.cshtml部分
@section Scripts{
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<script type="text/javascript" language="JavaScript">
var SetStatClicked;
$(document).ready(function () {
SetStatClicked = function (strType, strBillID) {
$.ajax(
{
type: "GET",
url: '@Url.Action("OnSetStat", "Home")' + "?StatType=" + strType + "&BillID=" + strBillID,
contenType: "application/json",
dataType: "json",
success: function (response) {
alert(response);
},
failure: function () {
alert('失败,请重试一下或与系统维护员联系!');
}
}
)
}
})
</script>
}
在controllers中
public JsonResult OnSetStat(string StatType,string BillID)
{
string SqlStr = "";
if (StatType == "Accept")
SqlStr = string.Format("UPDATE WorkList SET IsToBe=1,IsDelete=0,IsFinish=0 WHERE Id={0}", BillID); ..... int returnEffectRow = ;
using (SqlConnection currentCon=new SqlConnection(UtilConf.Configuration.GetConnectionString("DefaultConnection")))
{
currentCon.Open();
using (var currentComm = currentCon.CreateCommand())
{
currentComm.CommandText = SqlStr;
returnEffectRow=currentComm.ExecuteNonQuery();
}
}
return new JsonResult(returnEffectRow);
}