1

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.

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. Commented Oct 27, 2014 at 1:44
  • $(this) is @html.actionlink defined as " @Html.ActionLink(modelItem.myfield, "controller", "action" new { OnClick = "SetTextBoxValue()" })" Commented Oct 27, 2014 at 1:48
  • 1
    Why use Html.Actionlink if you only need js code to execute? Commented Oct 27, 2014 at 2:19

2 Answers 2

2

try this :

@Html.ActionLink("LinkText", "#", "", null, new { onclick="SetTextBoxValue('mydata')" });

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, you have to do it as onclick="return SetTextBoxValue('mydate')"
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.