請分享ajax代碼,用於將多個複選框選中的值存儲到數組,並傳遞給控制器,而無需在MVC4中提交按鈕。請指導我。 在此先感謝ajax代碼用於將多個複選框值存儲到數組並傳遞給控制器
回答
用戶Jquery Ajax調用您的控制器的方法。
控制器代碼:
public class CustomerController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult UpdateOrder()
{
// some code
return Json(new { success = true, message = "Order updated successfully" }, JsonRequestBehavior.AllowGet);
}
}
jQuery代碼:
$.ajax({
url: '@Url.Action("UpdateOrder")', // to get the right path to controller from TableRoutes of Asp.Net MVC
dataType: "json", //to work with json format
type: "POST", //to do a post request
contentType: 'application/json; charset=utf-8', //define a contentType of your request
cache: false, //avoid caching results
data: {}, // here you can pass arguments to your request if you need
success: function (data) {
// data is your result from controller
if (data.success) {
alert(data.message);
}
},
error: function (xhr) {
alert('error');
}
});
上面的代碼作爲參考從這裏開始:
jQuery to call Action Method in ASP.NET MVC C# by Ajax
希望這會有所幫助。
儘管此鏈接可能回答問題,但最好在此處包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/ review/low-quality-posts/14403228) –
@VojtechRuzicka:感謝您指點我尋求更好的幫助。 –
但我找不到在您的答案發送選中的值到控制器的任何地方@Naresh Parmar – user777
- 1. ASP.NET MVC - 將多個複選框值傳遞給控制器
- 2. Cakephp將複選框數組傳遞給另一個控制器
- 3. 通過jquery/ajax將控制器的複選框值傳遞給控制器
- 4. 將複選框值傳遞給數組?
- 5. 使用ajax將複選框值傳遞給數組php
- 6. 將數組值從視圖傳遞給控制器使用ajax
- 7. 如何將值從複選框傳遞給控制器?
- 8. MVC3將複選框值的布爾型數組傳遞給控制器
- 9. 使用f:複選框將值從JSP傳遞到控制器
- 10. Angularjs將複選框值從一個控制器傳遞到其他控制器
- 11. 將多選列表框值傳遞給控制器
- 12. 如何通過mvc3中的ajax將複選框值傳遞給控制器
- 13. 傳遞多個複選框值控制器
- 14. 將複選框值傳遞給SQL Server存儲過程
- 15. 將控制值傳遞給控制器
- 16. MVC將模式數組傳遞給控制器使用jquery ajax
- 17. 使用ajax將字符串數組傳遞給mvc控制器
- 18. 使用jquery ajax post將數組傳遞給控制器失敗
- 19. 將數組傳遞給MVC控制器
- 20. 在Jstree中調用ajax複選框並將選中的數據傳遞給控制器(Codeignitor)
- 21. 如何使用jQuery將複選框值傳遞給數組?
- 22. 創建並將複選框數組傳遞給javascript函數
- 23. 將多個可選參數傳遞給控制器操作
- 24. 傳遞多個文本框值到控制器代碼點火器
- 25. 將PathVariable傳遞給AJAX控制器
- 26. 將值傳遞給控制器並返回到調用視圖?
- 27. 用BeginForm將值傳遞給控制器
- 28. Codeigniter將複選框數組值傳遞給mysql數據庫
- 29. 獲取多個複選框值,並傳遞給PHP jQuery中
- 30. 使用ajax將複選框值傳遞給jsp
你在網上看了嗎? – mike510a