[英]passing string from controller to view
This JavaScript code is being used to pass a string from a view to an action in a controller: 此JavaScript代码用于将字符串从视图传递到控制器中的操作:
<script type="text/javascript">
$(document).on('click', 'a', function () {
$.ajax({
type: 'POST',
url: '/brandsOfACategory',
contentType: 'application/json; charset:utf-8',
data: JSON.stringify(this.id)
})
});
</script>
brandsOfACategory
code in the controller: 控制器中的brandsOfACategory
代码:
public ActionResult brandsOfACategory(string id)
{
return View();
}
Code is not working as expected as id
is coming as null. 由于id
为null,因此代码无法正常工作。
Can someone please guide? 有人可以指导吗?
The code logic and syntax look fine. 代码逻辑和语法看起来不错。 To test: 去测试:
Steps 4 and 5 go away if you remove the alert. 如果删除警报,步骤4和5将消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.