我對MVC非常陌生。我有一個Html.Grid,裏面有一列。我想添加一個新的列,其標題是「新列」。這一列將有一個按鈕,每行都應該禁用該按鈕。根據另一列的值禁用該按鈕例如,如果某一行的「狀態」列爲「完整」,則應該啓用該按鈕,否則應該禁用該按鈕。點擊按鈕時,將會調用「MyController」中的「myMethod」。 在我看來,現有的代碼如下所示:在Html.Grid中添加按鈕列
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);
我已經加入這一行:
column.For(c => "<button onclick='location.href='www.gmail.com';'>gmail</button>").Named("My New Column").Encode(false);
,但它不是我working.When按一下按鈕,它不帶我去的鏈接。
有人可以幫我嗎?
當前禁用和啓用工作正常嗎? –
我無法在第一個位置添加列。啓用/禁用是次要的。我不知道如何在調用控制器中的Action的網格中添加按鈕。將列添加按鈕的示例代碼將很有幫助。 – user1550951
所以你的專欄顯示按鈕,而不是讓你鏈接,對不對? –