如何在asp.net mvc 3 razor / jquery中使用guid和jquery?

时间:2012-06-21 07:09:27

标签: jquery asp.net-mvc-3 razor

如何创建一个id作为按钮的newguid并在我的jquery脚本中使用它?类似的东西:

   @{ var id = Guid.NewGuid().ToString(); } //

<input type=button id="@id" name="Go" /> @*how can i use this newguid as an id for my button?*@

<script>
            @*how can i use this id to attach an eventhandler to for my button?*@
            $("@id ).click(function(){ 
            });
</script>

1 个答案:

答案 0 :(得分:3)

@{ var id = Guid.NewGuid().ToString(); }
<input type="button" id="@id" name="Go" />

和脚本:

<script type="text/javascript">
    $('#@(id)').click(function() { 
        alert('Thank you for clicking on button with id = ' + this.id);
    });
</script>