views:

1357

answers:

2

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 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 controler action is ..
public string linkfunction(string name)
{
    return  DateTime.Now.ToString();
}
A: 

This is similar to this:

http://stackoverflow.com/questions/488726/asp-net-mvc-ajax-actionlink-target-an-html-attribute

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

Daniel A. White
thanks, but my question confused you. i want to pass textbox1 value to my controler (as linkfunction parameter), so i need some way to pass textbox1.value in Ajax.ActionLink. i don't know how to do that.
Where you able to figure out how to accomplish the task? I'm in the same boat right now as you probably were; curious if you found a solution.
Geovani Martinez
A: 

I had this same problem, except I was using jQuery to make my ajax request:

$('#ajax-content').load('<%= this.Url.Action("Details", "Page", new { id = someJavascriptVariable }) %>');

I got it to work like this:

$('#ajax-content').load('<%= this.Url.Action("Details", "Page", ) %>' + '/' + someJavascriptVariable);

Or, in your case, it might look like this:

$('#ajax-content').load('<%= this.Url.Action("Details", "Page", ) %>' + '?name=' + textbox1.value);
davekaro