我用Kendo图书馆打破了我的想法。 我正试图做那样的事情:
c.Bound(m => m.Transaction).Title().ClientTemplate(Html.TransactionStateFormat(*currentValue*);
我的Html助手如下:
public static string TransactionStateFormat(this HtmlHelper helper, TransactionState value)
{
string result;
switch (value)
{
case TransactionState.Applied:
result = "# <img src='/Content/img/checkbox-circle-small-2.png'/> #";
break;
case TransactionState.OptOut:
result = "# <img src='/Content/img/cross-sircle-small.png'/> #";
break;
case TransactionState.Undefined:
result = "# N/A #";
break;
default:
result = "# N/A #";
break;
}
return result;
}
问题是如何获取Transaction
的当前值以将其放入html帮助器方法?或者如何通过另一种方式制作同样的东西?有什么建议吗?
答案 0 :(得分:2)
您可以使用以下
c.Bound(m => m.Transaction).Title().ClientTemplate("#=TransactionStateFormat(data)#");
public enum TransactionState: int
{
Applied = 0,
OptOut=1,
Undefined=2
}
并添加此javascript函数
<script>
function TransactionStateFormat(data)
{
var result='';
switch (data.Transaction)
{
case 0:
result = "<img src='/Content/img/checkbox-circle-small-2.png'/>";
break;
case 1:
result = "<img src='/Content/img/cross-sircle-small.png'/>";
break;
case 2:
result = "N/A";
break;
default:
result = "N/A";
break;
}
return result;
}
</script>
希望它会帮助你