Question

I'm using the MvcContrib Grid and I'd like to set the Visible property of columns depending on whether the corresponding col Id is present in a list of selected Col Id. In my View, I have the following function created

@functions {

    public bool testFn(int colId, String[] str)
    {
        String temp = colId.ToString(); 
        if (Array.Exists(str, s => s.Equals(temp))) {
            return true; 
        } else {
            return false;
        }
    }
}

and a str array also defined as follows

@{
var myStrArr = ViewBag.selCols as String[]; 
}

I'm calling the function from the Visible method of the Grid as follows

Visible(testFn(0, myStrArr))

The method however seems to completely ignore the value being returned. If I change my function to be simple as

public bool testFn(int colId, String[] str)
{
    String temp = colId.ToString(); 
    if (1 == 2) {
        return true; 
    } else {
        return false;
    }
}

and then call it exactly the same way from the Visible method, it seems to understand the false value being returned.

Can anybody help me resolve this please? I'm not sure what I am doing wrong. Stepping into the code shows me that the return value is correctly set to true or false depending on the inputs, but the Visible method seems to totally ignore the return value.

Thanks

Était-ce utile?

La solution

I have sorted this issue out now. Turns out it wasn't a problem with the Grid at all. Rather I had a missing line in my Ajax call that wasn't updating the Grid properly. Forgot to add $("#Grid).html(data); in the success function!

Thank you for Jeremy skinner for having a look at the issue for me (at MvcContrib google groups). Much appreciated.

Thank you all.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top