ASP.net MVC making cell contents as link in Grid.MVC

安稳与你 提交于 2019-12-18 03:27:06

问题


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.


回答1:


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());


来源:https://stackoverflow.com/questions/24059864/asp-net-mvc-making-cell-contents-as-link-in-grid-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!