admin管理员组文章数量:1336304
I have java script function
function SetTextBoxValue(data) {
$('#text_box').val($(this).val("myField"))
};
Is it possible, and how, to call only this function, WITHOUT controller and action names from @Html.ActionLink()
in razor view?
To extend a question, i have table and a form with 4 text boxes on same view. I need to fill one textbox with a value of a specific column in table when user click on link in that column.
I have java script function
function SetTextBoxValue(data) {
$('#text_box').val($(this).val("myField"))
};
Is it possible, and how, to call only this function, WITHOUT controller and action names from @Html.ActionLink()
in razor view?
To extend a question, i have table and a form with 4 text boxes on same view. I need to fill one textbox with a value of a specific column in table when user click on link in that column.
Share asked Oct 27, 2014 at 1:35 onedevteam.onedevteam. 4,17810 gold badges44 silver badges75 bronze badges 3-
The script does not make sense (what is
$(this)
in the context of the function?). Show the html and indicate what your trying to do. – user3559349 Commented Oct 27, 2014 at 1:44 - $(this) is @html.actionlink defined as " @Html.ActionLink(modelItem.myfield, "controller", "action" new { OnClick = "SetTextBoxValue()" })" – onedevteam. Commented Oct 27, 2014 at 1:48
-
1
Why use
Html.Actionlink
if you only need js code to execute? – David Tansey Commented Oct 27, 2014 at 2:19
2 Answers
Reset to default 2try this :
@Html.ActionLink("LinkText", "#", "", null, new { onclick="SetTextBoxValue('mydata')" });
Hope this helps.
You need 2 steps :
1 : add onclick="return someJsFct" in your actionLink
@Html.ActionLink("click here", "", "", null, new { onclick="return SetTextBoxValue('data')" });
2 : your javascript function must return false to prevent the actionLink from calling the server
<script language="javascript">
function SetTextBoxValue(data) {
// some code
return false;
}
</script>
本文标签: aspnet mvcHow to call ONLY javascript function in htmlactionlinkStack Overflow
版权声明:本文标题:asp.net mvc - How to call ONLY javascript function in html.actionlink - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742406085a2468849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论