Question: How do I add a link action inside a grid/column in MVC using Razor only

Question

How do I add a link action inside a grid/column in MVC using Razor only

Answers 1
Added at 2016-12-27 08:12
Tags
Question

I am using Razor grid system to show a listing. I want to make a column as a link action. But my problem is it's showing the link in the font end as raw HTML file. My code is

columns.Add(c => c.Title).Titled("Title").Filterable(true).RenderValueAs(c => Html.ActionLink(c.Title, "Details", new { id = c.Id }));

There fore the output is Output

I have also used Format() in placement of RenderValueAs() However the result is same. I have studied through from this links.Link1, Link1, Link1, Link1 But no probable solution is found. And I don't want to solve this without any help of javascript or any scripting language. I am looking for only razor related solution. Thank you.

Answers to

How do I add a link action inside a grid/column in MVC using Razor only

nr: #1 dodano: 2016-12-27 09:12

Never used this grid thing, just write html tag and loop myself, i think it's more in control.

In this case, i think it's RenderValueAs method problem, it maybe decode output.
You can try this RenderValueAs(c => {string tag = generate your link tag string; return Html.Raw(tag);})

if it is not working you can write a extension method on Filterable(), generate MvcHtmlString yourself, it should work.

Source Show
◀ Wstecz