MVCContrib grid - select row

I have an MVCContrib grid that displays the selected properties from an Account object. I want the user to select a row and move to another page to view the full properties of the object represented by the row they clicked. How to add the selected action to the grid lines?

+3
source share
2 answers

Today I ran into a similar problem.

You can use .RowAttributes. In this way:

Html.Grid(Model).Columns(column => 
{
    column.For(e => e.Id); 
    column.For(e => e.Message); 
})
.RowAttributes(x => new Dictionary<string, object>
    {{"onClick", "window.location.href = 'google.com'"}})
.Render();

As a result, when you click on it, it will run javascript "onclick" and open google. You can change the URL to transfer to Id with "x" in Lamda.

+3

Grid MVC3, :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcContrib;
using MySolution.ViewModels;

namespace MySolution.Models.Extensions
{
public static class RowAttributeExtensions
{
    public static Hash GetRowAttributes(this MySolution.ViewModels.Model)
    {

        string onclickFunctionBody = "{window.location.href = '/MyController/MyAction?id=" + Model.Id + "'; return false;}";
        Hash hash = new Hash(onclick => onclickFunctionBody)
        return hash;
    }
}
}

:

@Html.Grid(Model).RowAttributes(row => row.Item.GetRowAttributes()).Columns(column =>
{
    column.For(c => c.Col1);
    column.For(c => c.Col2);
    ...
})
+3

Source: https://habr.com/ru/post/1747071/


All Articles