I am very new to MVC. I have an Html.Grid with some column in it.I want to add a new column with its heading as "New Column".This column will have a button for each row.The button should be disabled based on the value of another column.For example,if 'status' column for a row is "complete",then the button should be enabled otherwise it should be disabled. When the button is clicked,"myMethod" in "MyController" will be called. The existing code in my View looks like this:
Html.Grid(Model.Results)
.RowAttributes(row => new Hash(@class => row.Item.Priority1 ? "redgrid" : row.IsAlternate ? "alternategrid" : "grid"))
.Columns(column =>
{
column.For(c =>
(c.ExistsInPatRec == true) ?
Html.ActionLink(c.CaseNumber.ToString(), "Details", new { id = c.CaseNumber }, new { target = "_blank" })
: Html.Label(c.CaseNumber.ToString())
)
.Named("Case Number").SortColumnName("CaseNumber")
.Encode(false)
;
//I have to add my column here.It will be disabled if "Status"="Incomplete"
column.For(c => c.Status).Named("Status").SortColumnName("Status")
.Attributes(x =>
{
if (x.Item.Status == "Complete")
return new Hash(style => "background-color:#33CC00");
else if (x.Item.Status == "Incomplete")
return new Hash(style => "background-color:orange");
else
return new Hash(style => "");
});
column.For(c => c.SomeId);
I have added this line:
column.For(c => "<button onclick='location.href='www.gmail.com';'>gmail</button>").Named("My New Column").Encode(false);
but it's not working.When I click the button,it doesnt take me to the link.
Can someone help me please?
Did not yet go through your entire code but try this:
Change:
To:
This should at least make your links work. Your links were not working since your buttons were not properly formed.
To trigger Controller Actions, you need to use the following type of code.