This is my method:
$(document).ready(function () {
$('td.clickableCell').click(function () {
var currentObject = null;
currentObject = $(this).text();
@Html.ActionLink("GetThis", "Get", new {theName = currentObject} )
});
});
but it says that currentObject doesn’t exist in the current context. How to resolve this?
Instead of
@Html.ActionLinkyou should use the jQuery.get function. `@Html.ActionLink is run on the server whereas the javascript is run on the client.The
Url.Actionis rendered on the server and will give you the appropriate url. The$.getwill run agetrequest on the client.Keep in mind, if this javascript is in a
.jsfile, theUrl.Actionwill not be run. In that case you may simply want to replace it with/Get/GetThisor render the url in a hidden field on the page and get the value of the hidden field in your.jsfile.You need an action method that looks like this in order to access the parameter: