admin管理员组文章数量:1394409
I have this action link in view:
@Html.ActionLink("Edit", "Edit", null, new {@id="editLink", @class="button"})
I would like to call a java script method to make the URI at runtime from my Selected List Box Item.
@Html.ListBox("EmployeeName", (IEnumerable<SelectListItem>)ViewBag.selectlist, new { @id = "saglistbox", @class = "SAGListbox" })
As a first step, when i am trying to just display an alert using JavaScript:
<script type="text/javascript">
$('#editLink').click(function () {
alert("hello");
});
</script>
For some reason this is not working as expected.
I have this action link in view:
@Html.ActionLink("Edit", "Edit", null, new {@id="editLink", @class="button"})
I would like to call a java script method to make the URI at runtime from my Selected List Box Item.
@Html.ListBox("EmployeeName", (IEnumerable<SelectListItem>)ViewBag.selectlist, new { @id = "saglistbox", @class = "SAGListbox" })
As a first step, when i am trying to just display an alert using JavaScript:
<script type="text/javascript">
$('#editLink').click(function () {
alert("hello");
});
</script>
For some reason this is not working as expected.
Share Improve this question edited Jul 15, 2013 at 13:37 anar khalilov 17.5k9 gold badges51 silver badges63 bronze badges asked Jul 15, 2013 at 13:25 SrinivasSrinivas 2,53910 gold badges48 silver badges70 bronze badges3 Answers
Reset to default 5You were not binding event at when DOM is pletely loaded.
<script>
$(function () {
$('#editLink').click(function () {
alert("hello");
//To get selected value use
var selected = $("#EmployeeName").find(':selected').text();
//To stop default behaviour
return false;
});
});
</script>
Second make the URI at runtime from my Selected List Box Item
then you have to stop it default behavior thus used return false
Try this:
<script type="text/javascript">
$(document).ready(function()
{
$('#editLink').click(function ()
{
alert("hello");
});
});
</script>
You can pass any html attribute as parameter to generate the action link. You can do this as well:
@Html.ActionLink("Edit", "Edit", null, new { @id="editLink", @class="button", onclick = "myfunction()" })
本文标签: javascriptASPNET MVC RAZOR ActionLink clickStack Overflow
版权声明:本文标题:javascript - ASP.NET MVC RAZOR ActionLink click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744613592a2615801.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论