c# - 将参数传递给 ASP.NET Core 中的 jQuery 加载函数
问题描述
我想id
在控制器中传递这个动作的参数
public IActionResult BuildingDetail(int id)
{
return PartialView("_BuildingDetailsPartial", _buildingRepository.GetById(id));
}
进入这个load
方法是为了运行AJAX。
@section Scripts{
<script type="text/javascript">
$(document).ready(function () {
$("#LoadBuildingDetail").click(function () {
$("#BuildingDetail").load("/employees/buildingdetail/id");
});
})
</script>}
我是 jQuery 的新手,但我想我需要在将id
vaule 传递给加载函数之前以某种方式存储它,所以controller/action/parameter
方法不起作用。但是atm我没有运气。
解决方案
如果你想通过 jquery 方法将 id 传递给控制器,你可以将它作为对象load
直接传递给方法。load
我假设您在页面上的某处有 id 的值,或者您正在使用模型中的剃刀语法在视图中对其进行硬编码。
无论如何,请尝试在您的 jquery 中使用类似的东西
//passing id's value from the control on the page
$("#BuildingDetail").load("/employees/buildingdetail", { id: $("#Id").val() });
或者
//passing id's value from the Model property
$("#BuildingDetail").load("/employees/buildingdetail", { id: @Model.Id });
参考:jQuery加载方法
推荐阅读
- apache-kafka - 当应用程序没有完成偏移提交时kafka流应用程序的行为(并且自动提交关闭)
- c - 如果我使用 execl() 运行它,如何获得 /bin/ls -R 的返回值?
- jwt - 当 secretOrKey 不可用时在 Nestjs 中使用 JwtStrategy
- c++ - 单例模式 - 共享库中的符号和动态加载
- flutter - 你如何在颤振中添加一张卡片?
- sql - 加入 3 个表,从 2 个不同的表和按材料名称分组的总数量
- python - 展开页面顶部的画布
- javascript - 如何使用 fetch 在本地 json 文件中发布?
- amazon-redshift - Redshift中的存储过程不显示任何内容
- javascript - 如何比较javascript中的两个对象数组并更新值?