Datatables with asp.net mvc rendering Url.actions/html.actionlinks with route values
Datatables with asp.net mvc rendering Url.actions/html.actionlinks with route values
tomzn
Posts: 29Questions: 9Answers: 2
Hi,
I am using datatables to render a table with server side asp.net mvc razor views. I am using the render function to display urls for "editing" rows on the table -
render": function (data, type, row) {
return '<a href=\"LinkedAccountsDetails/' + data + '\">Edit</a>';
}
How do I use url.actions with routevalues instead of hardcoding the urls like above. I am able to get url.actions without routevalues to work but when i try and concatenate the data variable as a route value it doesn't work.
Thanks
This discussion has been closed.
Replies
Ok. Managed to solve this. This is what I did :
Hi,
Thanks for posting back - great to hear you for it working.
Allan
Hi tomzn,
I have tried your solution, but it turn out as string.
@Fitri - If you show us your code or a test case perhaps we can identify the issue.
Allan
this is my code:
when I hover to this link it shows "https:/abc/@Url.Action("
Sounds like the
@Url.Action
isn't being interpreted (filled in) by the server-side. I'm afraid my .NET knowledge doesn't extend to knowing why that might be. That might be a good one to ask on StackOverflow as I think that is more .NET rather than a DataTables question.Regards,
Allan
Hi Fitri
I have the same problem.
Did you ever solve this?
Hello guys,
I know this might come in late, but this is how it can work with MVC. Depending how you setup your routing
The key here is "defaultContent" suppose to allow you enter HTML-code for let's say a button. Then you add a jQuery function that reacts onclick event for that button. Within the function you can capture each row's data through table.row($(this).parent('tr').data(). Depending how your JSON data looks like you can then dig deeper into your model. In my example it's data.ID
Finally the onclick event can redirect in the MVC-model through the classic window.location.
Hope that helps.