Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an input value or JavaScript variable in ASP.NET MVC Ajax.ActionLink

I want to pass an input control value (say textbox1.value or a javascript variable) to a controller action method (as a parameter) without a form post (using Ajax.ActionLink). Please see the code below.

Is it possible to assign something like new {name = textbox1.value} in Ajax.ActionLink.

View

<input type="text" id="textbox1" />
<%= Ajax.ActionLink("mylink", "linkfunction", new {name = textbox1.value}, new AjaxOptions { UpdateTargetId = "result"}) %>
<span id="result"></span>

and controller action is:

public string linkfunction(string name)
{
    return  DateTime.Now.ToString();
}

1 Answers

This is similar to this:

ASP.NET MVC : AJAX ActionLink- Target an HTML attribute

Plus, you don't need to pass in the control name into your Action.

like image 51
Daniel A. White Avatar answered Sep 22 '26 11:09

Daniel A. White