Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MVC2-在页面上javascript函数中传递C\35;代码_Javascript_Function_Asp.net Mvc 2_Escaping - Fatal编程技术网

MVC2-在页面上javascript函数中传递C\35;代码

MVC2-在页面上javascript函数中传递C\35;代码,javascript,function,asp.net-mvc-2,escaping,Javascript,Function,Asp.net Mvc 2,Escaping,我有一个输入按钮,单击一次我想启动一个javascript函数并传递我的C#object属性。它包含一个我在Ajax函数中需要的ID。我在正确转义我的引用时遇到问题 <td><input type="button" value='Contact query' onclick="sendQuery"'(<%=Model.AssociatedLists[0].Id.ToString()%>)'"/></td> function sendQuery

我有一个输入按钮,单击一次我想启动一个javascript函数并传递我的C#object属性。它包含一个我在Ajax函数中需要的ID。我在正确转义我的引用时遇到问题

 <td><input type="button" value='Contact query' onclick="sendQuery"'(<%=Model.AssociatedLists[0].Id.ToString()%>)'"/></td>

 function sendQuery(param) {
        alert(param);
    }

我的按钮没有启动,因为我的HTML格式不正确


有什么需要帮忙的吗?

这应该可以

onclick="sendQuery('<%=Model.AssociatedLists[0].Id.ToString()%>')"
onclick=“sendQuery(“”)”
而不是

<input type="button" value='Contact query' onclick="sendQuery"'(<%=Model.AssociatedLists[0].Id.ToString()%>)'"/>

删除
onclick
引用,在按钮上添加id,然后尝试以下操作:

<script type="text/javascript">     
    $(document).ready(function () {
        $('#your-button-id').click(function () {
            sendQuery(<%=Model.AssociatedLists[0].Id.ToString() %>);
        });
    });
</script>

$(文档).ready(函数(){
$(“#您的按钮id”)。单击(函数(){
sendQuery();
});
});

谢谢,这很有效。我很困惑,因为visual studio在有(‘and’)的地方给了我红色的swiggly。但在浏览器中它可以工作。也许我遗漏了一些东西,但除了为我的答案添加上下文之外……你还添加了什么吗?对我来说,这似乎只是一个副本,更糟糕的是,它被认为是正确的答案。
<input type="button" value='Contact query' onclick="sendQuery('<%=Model.AssociatedLists[0].Id.ToString()%>')"/>
<script type="text/javascript">     
    $(document).ready(function () {
        $('#your-button-id').click(function () {
            sendQuery(<%=Model.AssociatedLists[0].Id.ToString() %>);
        });
    });
</script>