繁体   English   中英

将参数传递给ASP.NET Core中的jQuery加载函数

[英]Pass parameter to jQuery load function in ASP.NET Core

我想通过此操作在控制器中传递一个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,然后再将其传递给load函数,因此controller/action/parameter方法不起作用。 但是atm我没有运气。

如果要通过jquery的load方法将id传递给控制器​​,则可以将其作为对象直接传递给load方法。

我假设您在页面的某处具有id的值,或者您正在使用模型中的razor语法在视图中对其进行硬编码。

无论如何,请尝试在您的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加载方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM