javascript - 在 asp.net.core c# 中通过 ajax 命令将布尔值发送到控制器
问题描述
我在视图部分有一个带有复选框类型输入的表单
<div class="checkbox">
<label class="">active</label>
<div class="icheckbox_flat-green checked" style="position: relative;">
<input type="checkbox" id="AdvActive" name="AdvActive" class="flat" checked="checked"/>
</div>
</div>
并通过下面的ajax代码将值发送到控制器
$.ajax({
type: "post",
url: '@Url.Action("CreateAdvBanner", "Advertise")',
cache: false,
data: form.serialize()
})
除同一个复选框外,所有表单值都发送到控制器。当复选框被选中时,我想向控制器发送“True”吗?这是我的控制器
[HttpPost]
public IActionResult CreateAdvBanner(string AdvCode, int AdvPrice ,int AdvDay, string AdvDesc,bool AdvActive)
{
解决方案
将 JSON 发送到控制器
就像是
$.ajax({
type: "post",
url: '@Url.Action("CreateAdvBanner", "Advertise")',
cache: false,
data: {"AdvCode" : "itsValue", "AdvPrice":"itsValue", "AdvDay" : "itsValue", "AdvDesc" : "somevalue"}
})
布尔值和数字不能在“”中
推荐阅读
- pdf - Google APP Script 突然将 PDF 导出为 text/html
- android - 在构建期间从 gradle 插件禁用任务
- php - 无法解码 JWT 令牌 PHP
- python - Matplotlib 找不到字体
- c - 如何创建一个二维数组来存储从 C 中的 .txt 文件扫描的单词集合?
- c# - 如何将 T 转换为特定对象
- pytorch - 如何找到torch.solve的源代码?
- mongodb - 如何填充 Mongooese 数组中的字段?
- c++ - OpenCV Mat 矩阵和 Eigen 矩阵之间的数据不匹配
- django - React 前端的 Rest-framework ID 问题以“颜色是,颜色否”模式显示数据