This is a migrated thread and some comments may be shown as answers.

[Solved] Having trouble creating link in HtmlAttributes

0 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Evan
Top achievements
Rank 1
Evan asked on 10 Aug 2012, 08:22 PM
Good afternoon everyone,

I'm having trouble setting up links inside of a grid. I want to turn the values in a particular column into hyperlinks. Earlier, I tried using a template to turn the values into likes like so:
columns.Bound(model => model.Value).Title("Details")
.Template(model =>
   {
       return "<a href = *epicly long link*" + model.linkID>" + model.Value+ "</a>";
   });

And that worked most of the time. However, some of the grids have multiple pages, and when you go to a different page, the links turn into plain text. So instead, I tried using HtmlAttributes to set up the links, and the probably with the links disappearing went away, but now I'm having trouble getting the value from "model". I tried doing this in many ways:

columns.Bound(model => model.Value).Title("Details") 
.HtmlAttributes(new { onclick = "javascript:window.location='*long link again*" + model.linkID+"'"});

.HtmlAttributes(new { onclick = "javascript:window.location='*long link again*" + model=>model.linkID+"'"}); 

and a few other ways using model (like putting model =>  out in front of new and several other places) but I got errors like "lambda expressions are not a delegate type, cannot convert to string" and such. I also tried things like:

columns.Bound(model => model.Value).Title("Details") 
.HtmlAttributes(new { onclick = "javascript:window.location='*long link again*" + @item.linkID+"'"});

but again, I got errors saying "item does not exist in this context".

Is there any way to retrieve these values within HtmlAttributes or do I need to find a way to make Template work?
Tags
Grid
Asked by
Evan
Top achievements
Rank 1
Share this question
or