Maksims
Maksims

Reputation: 167

Need assistance with RAZOR

I have list of product, and when I need to edit something I click on button edit at right of product name. How I can I do clickable entire row.

Now I have <td><b>@Html.ActionLink(Products.Resources.Properties.Literals.Edit, "Edit", new { id = items[i].Template.Id })</b></td>

But I want to do all clickable.

Upvotes: 2

Views: 52

Answers (2)

Roberto Conte Rosito
Roberto Conte Rosito

Reputation: 2108

You have to use just a little bit of javascript to do it.

Using pure javascript you can add an event on "tr" element of your html:

<tr onclick="document.location='@Url.Action(Products.Resources.Properties.Literals.Edit, "Edit", new { id = items[i].Template.Id })'">
    <td><b>Edit</b></td>...
</tr>

In this way the entire row is now clickable. Using jquery you can do more:

<tr data-link="@Url.Action(...)">
   <td><b>Edit</b></td>
</tr>

Your jquery code should look like this:

$('tr[data-link]').on('click', function() {
  document.location = $(this).attr('data-link');
});

I think the second solution is the most elegant and easiest to implement when needed.

Hope this can help.

Upvotes: 1

funbrigade
funbrigade

Reputation: 321

You need to attach a click handler to the tr - making the entire tr a link would be invalid markup and wouldn't work, anyways.

There are a number of ways to do this and I'm not really sure what your JS setup looks like, so I recommend looking into what your framework/libraries offer (for example, if you're using jQuery, look into something like:

$('tr').on('click', function($event) {
    // ...
});

Good luck!

Upvotes: 0

Related Questions