Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass a Textboxes value to my Ajax.ActionLink?

In my ASP.NET MVC application I want a user to add a value into a textbox and then press my Ajax.ActionLink. I want to do something like this:

Ajax.ActionLink("Go", "Action", "Controller", new { value = textbox1.value })

Or how else can I get this textbox value back to my action? Jquery?

like image 507
Whozumommy Avatar asked May 15 '09 06:05

Whozumommy


1 Answers

You may run action using AJAX $.get method:

<script type="text/javascript">     

    $(document).ready(function()
    {
        $("#t").change(function()
        {
            RunAction();
        });

        RunAction();
    });

    function RunAction()
    {
        var action = '<%= Url.Action("Action", "Controller") %>';
        var data = $("#t").serialize();
        $.get(action, data);
    }

</script>

<input type="text" id="t" />
like image 124
Alexander Prokofyev Avatar answered Oct 03 '22 04:10

Alexander Prokofyev