c# - 如何从asp.net核心MVC jquery中的链接隐藏Id参数?
问题描述
这是我重定向到我的视图的脚本
<script>
$(document).on('click', '.btndetail', function () {
var id = $(this).data("id");
var url = "/Schools/SchoolDetails/Id=" + id;
window.location.href = url;
}
);
</script>
和 id 进入控制器
[HttpGet]
public IActionResult SchoolDetails(string Id)
{
return View();
}
但是 ID 显示在链接中,我该如何隐藏它?
解决方案
您需要实现 ajax 方法,使用 GET 进行异步调用,请参阅此文档: http ://api.jquery.com/jquery.ajax/
这是在您的代码中实现的示例:
$(document).on('click', '.btndetail', function () {
var id = $(this).data("id");
var url = '@Url.Action("SchoolDetails", "Schools")';
$.ajax({
type: "GET",
url: url,
data: { Id = id },
success: function (data) {
// Success Here
window.location.href = url;
},
error: function (data) {
alert("Error!");
}
})
})
推荐阅读
- java - 如何让 Java 声音 API 从 jar 中工作
- css - 我不能使用@font-face
- jquery - 我使用猫头鹰旋转木马,在移动视图中我只想显示单个项目。但是当我单击下一个按钮时,第二个项目从左侧剪切
- python - django:上传的图片不会显示
- python - How to fill up a matrix in Python using for loops
- c# - 从具有特定模式的文本文件中读取文本
- arrays - 在 Spark 数据框中过滤 json 数组数据
- spring-boot - 生成没有密码的 JWT OAuth2 访问令牌
- java - 如何找出 json 响应是 android 中的空 JSON 对象?
- javascript - 将 PHP $_POST 数组传递给 javascript/jQuery 以通过 ajax 发送回 PHP