开发者

MVCContrib grid - select row

开发者 https://www.devze.com 2023-01-01 13:14 出处:网络
I have a MVCContrib grid that shows selected properties from an Account object.I want the user to select a row and be taken to another page to view the full properties of the object represented by the

I have a MVCContrib grid that shows selected properties from an Account object. I want the user to select a row and be taken to another page to view the full properties of the object represented by the row th开发者_StackOverflowey clicked. How do I add a .Selected action to the rows of the grid?


I just came across a similar problem today.

You can use the .RowAttributes Like so:

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

In result, when you click on a it will trigger the javascript "onclick" and open up google. You can change the url to pass in an Id by using the "x" in the Lamda.


If you're using the Grid in an MVC3 context, you can also accomplish this via an extensions class on the server side:

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;
    }
}
}

and on the client side this will take the form of:

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

精彩评论

暂无评论...
验证码 换一张
取 消