Reputation: 1853
I am developing an ASP.net MVC application.
Earlier I used the following code to display a table of products.
foreach (var item in Model)
{
<div class="row">
<div class="cell">
@Html.ActionLink(item.productName, "ViewProduct", "Showcase",
new { productID = item.productID }, null)
</div>
<div class="cell">
@item.quantity
</div>
<div class="cell">
@item.price
</div>
</div>
}
It worked fine, I was able to make the Nx1'st element as a link to redirect to the view that displays the product's details.
Then I wanted to implement GridView to display products table using MVC.Grid Nuget package.
Grid works fine but I can't make the Nx1'st element as link so that I can redirect.
I tried out this but it's not working.
@Html.Grid(Model).Columns(columns =>{
columns.Add(model => model.productName).Titled("Name").Filterable(true)
.RenderValueAs(o => Html.ActionLink(o.productName, "ViewProduct", "Showcase",
new { productID = o.productID }, null));
columns.Add(model => model.quantity).Titled("Quantity Available");
columns.Add(model => model.price).Titled("Price");
}).WithPaging(3).Sortable(true)
The output that I get in the Nx1 cell is:
<a href="/Showcase/ViewProduct/?productID=15">Galaxy Note 3</a>
Desired output: Galaxy Note 3
Please help me out. Thanks.
Upvotes: 14
Views: 20319
Reputation: 1853
This solved the problem
columns.Add(model => model.productName).Titled("Name")
.Filterable(true).Sanitized(false).Encoded(false).
RenderValueAs(model => Html.ActionLink(model.productName,
"ViewProduct", "Showcase", new { productID = model.productID }, null)
.ToHtmlString());
Upvotes: 18