admin管理员组文章数量:1290318
I looked at other question: how to call javascript function in html.actionlink in asp mvc? showing how to add onclick
to @Html.ActionLink
but in my case function I assigned to onclick
is never invoked.
I tried these action links:
<p>@Html.ActionLink("Call number", "Call", new { id = Model.Id, number = Model.CellNumber, onclick = "javascript:alert(a);" }, new { @class = "btn btn-default" })</p>
<p> @Html.ActionLink("Call number »", "Call", new { id = Model.Id, number = Model.SecondaryPhoneNumber, onclick = "javascript:Call();" }, new { @class = "btn btn-default" })</p>
and the function looks like:
<script>
function Call(){
alert("BLA");
}
</script>
but no alert is shown in both cases(first and second button). Besides that action link wroks.
Question: What I did wrong?
EDIT:
Action links in html look like that and the look corrupted:onclick=Call%28%29%3B
<p><a class="btn btn-default" href="/Person/Call/7?number=113-456-789&onclick=alert%28a%29%3B">Call Cell Phone</a></p>
<p> <a class="btn btn-default" href="/Person/Call/7?number=98873213&onclick=Call%28%29%3B">Call Client's Secondary Number »</a></p>
and the function looks like it should:
<script>
function Call(){
alert("BLA");
}
</script>
I looked at other question: how to call javascript function in html.actionlink in asp mvc? showing how to add onclick
to @Html.ActionLink
but in my case function I assigned to onclick
is never invoked.
I tried these action links:
<p>@Html.ActionLink("Call number", "Call", new { id = Model.Id, number = Model.CellNumber, onclick = "javascript:alert(a);" }, new { @class = "btn btn-default" })</p>
<p> @Html.ActionLink("Call number »", "Call", new { id = Model.Id, number = Model.SecondaryPhoneNumber, onclick = "javascript:Call();" }, new { @class = "btn btn-default" })</p>
and the function looks like:
<script>
function Call(){
alert("BLA");
}
</script>
but no alert is shown in both cases(first and second button). Besides that action link wroks.
Question: What I did wrong?
EDIT:
Action links in html look like that and the look corrupted:onclick=Call%28%29%3B
<p><a class="btn btn-default" href="/Person/Call/7?number=113-456-789&onclick=alert%28a%29%3B">Call Cell Phone</a></p>
<p> <a class="btn btn-default" href="/Person/Call/7?number=98873213&onclick=Call%28%29%3B">Call Client's Secondary Number »</a></p>
and the function looks like it should:
<script>
function Call(){
alert("BLA");
}
</script>
Share
Improve this question
edited May 23, 2017 at 10:27
CommunityBot
11 silver badge
asked Sep 6, 2014 at 18:26
YodaYoda
18.1k72 gold badges216 silver badges367 bronze badges
3
-
1
you dont need to add
javascript:
to an onclick. You would only do this for ahref
target on a link. e.g. eitheronclick="Call()"
orhref="javascript:Call()"
. You can see this in the answer to [stackoverflow./questions/2856071/… – Rhumborl Commented Sep 6, 2014 at 18:29 -
@Rhumborl This is the answer I used before I asked question here and did not work. Please see my edit it looks like that html browser sees gets something like that:
onclick=Call%28%29%3B
– Yoda Commented Sep 6, 2014 at 18:37 - @JLRishe I posted HTML in EDIT at the bottom of OP it seems the name of function is corrupted there. I added link to the answer I used to solve the problem before I asked question here. – Yoda Commented Sep 6, 2014 at 18:39
1 Answer
Reset to default 6You add onclick handler in wrong place. You must put it in Html Attributes
block instead Route values
.
Try it:
<p>@Html.ActionLink("Call number", "Call", new { id = Model.Id, number = Model.CellNumber }, new { @class = "btn btn-default", onclick = "alert('a');" })</p>
本文标签:
版权声明:本文标题:Html.ActionLink onclick JavaScript function is not invoked and name of function is corrupted in output HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741496312a2381849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论