javascript - The name parametor does not exist in the current context in JQUERY method -
i have button , when clicked process event have been called , parameter passed event.
here code:
<input type="button" value="accessing layers" onclick="process('accessinglayers');" /> function process(actionname) { $.ajax({ url: '@url.action(actionname)', type: 'post', data: { sessionid: parent.parent.mapframe.sessionid, mapname: parent.parent.mapframe.mapname }, success: function (result) { alert('successfully passed data controller'); } }); } but in row:
url: '@url.action(actionname)' i error:
the name 'actionname' not exist in current context
any idea why error above?
and how fix it?
remember razor code executes on server before client side code gets executed. cannot pass javascript variable razor method that.
if still want build url using url.action helper method , pass process method, should call url.action method correct arguments(the action method,controller name etc..) , generate url , pass url( generated razor) javascript method string parameter value
<input type="button" value="accessing layers" onclick="process('@url.action("accessinglayers")')" /> and js code
function process(actionurl) { $.ajax({ url: actionurl, // existing code }); }
Comments
Post a Comment