.Net Core下使用Ajax,并传送参数到controllers
程序员文章站
2022-05-25 14:21:38
可以使用URL拼接方式方法传参 .cshtml部分 在controllers中 ......
可以使用URL拼接方式方法传参
.cshtml部分
1 @section Scripts{ 2 @{ await Html.RenderPartialAsync("_ValidationScriptsPartial");} 3 <script type="text/javascript" language="JavaScript"> 4 var SetStatClicked; 5 $(document).ready(function () {
SetStatClicked = function (strType, strBillID) { 6 $.ajax( 7 { 8 type: "GET", 9 url: '@Url.Action("OnSetStat", "Home")' + "?StatType=" + strType + "&BillID=" + strBillID, 10 contenType: "application/json", 11 dataType: "json", 12 success: function (response) { 13 alert(response); 14 }, 15 failure: function () { 16 alert('失败,请重试一下或与系统维护员联系!'); 17 } 18 } 19 )
} 20 }) 21 </script> 22 }
在controllers中
1 public JsonResult OnSetStat(string StatType,string BillID) 2 { 3 string SqlStr = ""; 4 if (StatType == "Accept") 5 SqlStr = string.Format("UPDATE WorkList SET IsToBe=1,IsDelete=0,IsFinish=0 WHERE Id={0}", BillID); 6 7 ..... 8 9 int returnEffectRow = 0; 10 using (SqlConnection currentCon=new SqlConnection(UtilConf.Configuration.GetConnectionString("DefaultConnection"))) 11 { 12 currentCon.Open(); 13 using (var currentComm = currentCon.CreateCommand()) 14 { 15 currentComm.CommandText = SqlStr; 16 returnEffectRow=currentComm.ExecuteNonQuery(); 17 } 18 } 19 return new JsonResult(returnEffectRow); 20 }
下一篇: Python中super的用法实例