ASP.net MVC使单元格内容成为Grid.MVC中的链接 [英] ASP.net MVC making cell contents as link in Grid.MVC
本文介绍了ASP.net MVC使单元格内容成为Grid.MVC中的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发ASP.net MVC应用程序.
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>
}
一切正常,我能够将Nx1的第一个元素作为链接重定向到显示产品详细信息的视图.
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.
然后我想实现GridView以使用MVC.Grid Nuget包显示产品表.
Then I wanted to implement GridView to display products table using MVC.Grid Nuget package.
网格可以正常工作,但是我无法将Nx1的第一个元素作为链接来进行重定向.
我尝试了这个,但是没有用.
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)
我在Nx1单元中得到的输出是:
The output that I get in the Nx1 cell is:
<a href="/Showcase/ViewProduct/?productID=15">Galaxy Note 3</a>
所需的输出: Galaxy Note 3
请帮帮我.谢谢.
推荐答案
这解决了问题
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());
这篇关于ASP.net MVC使单元格内容成为Grid.MVC中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文