[英]Make table row clickable to get controller action using javascript and mvc
Im trying to make a table row clickable using javascript. 我正在尝试使用JavaScript使表格行可点击。 I have a table with customers and when the row is clicked, it should forward to the detals view.
我有一个带有客户的表,当单击该行时,它应该前进到详细视图。 But now im stuck with the javascript.
但是,现在我停留在javascript上。 First of all I cant seem to get the id of the row.. and second it dosent seem to call the Details method in the Customer controller... my javascript:
首先,我似乎无法获取该行的ID ..其次,它似乎没有在Customer控制器中调用Details方法...我的JavaScript:
<script type="text/javascript">
$(document).ready(function(){
$('#customers tr').click(function () {
var id = $(this).id;
$.ajax({
url: '@Url.Action("Details","Customer")',
type: 'GET',
data: { id: id }
});
})
})
to get the id you need to do: 获取您需要执行的ID:
var id = $(this).attr( 'id' );
not sure about the other part, can you view the source in browser and verify the url? 不确定其他部分,可以在浏览器中查看源代码并验证网址吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.