I would like to be able to pass the data from a text box on a page to tan Action using ActionLink.
I specify the actionLink as follows in my view
@Ajax.ActionLink(
"UTC",
"GetTime",
{ zone="BST" },
new AjaxOptions {
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "TargetElementID",
OnBegin = "GetTime_OnBegin",
}
)
Since I cannot see any way to specify this in the helper I thought to implement the OnBegin event and do it there. I noted that OnBegin receives XMLHttpRequest, containing details of the request that will be performed and an object, whos purpose escapes me, but contains a url property object.url as well as object.context.url, So I thought to add the property I need to pass to my action to the url, thinking it would resolve to the same-named parameter of the action.
function GetTime_OnBegin(XMLHttpRequest, object) {
object.context.url = object.context.url + "&text=" + $('TextBoxId').val();
}
My controller action
public string GetTime(string zone, string text) {
DateTime time = DateTime.UtcNow;
return string.Format(
"{0:h:mm:ss tt}({1},{2})",
time, zone.ToUpper(),text);
}
However text is not being passed and is always null.
Is there a more elegant way to do this ?