Passing a JavaScript variable to a helper method

1k views Asked by At

I am using ASP.NET MVC 3 and the YUI library.

I created my own helper method to redirect to an edit view by passing in the item's ID from the Model as such:

window.location = '@Url.RouteUrl(Url.NewsEdit(@Model.NewsId))';

Now I am busy populating my YUI data table and would like to call my helper method like above, not sure if it is possible because I get the item's ID by JavaScript like:

var formatActionLinks = function (oCell, oRecord, oColumn, oData) {
   var newsId = oRecord.getData('NewsId');
   oCell.innerHTML = '<a href="/News/Edit/' + newsId + '">Edit</a>';
};
1

There are 1 answers

0
Gideon On BEST ANSWER

Store your URL with some custom ID, which you'll now to replace later on:

var myurl = '@Url.RouteUrl(Url.NewsEdit(0))'; //Let's use zero

later on:

var formatActionLinks = function (oCell, oRecord, oColumn, oData) {
   var newsId = oRecord.getData('NewsId');
   //lets use the url we defined above, and replace the zero with our id.
   oCell.innerHTML = '<a href="' + myurl.replace('0',newsId)+ '">Edit</a>';

};