gpt4 book ai didi

c# - 如何在名称中指定带有 - 的属性

转载 作者:太空狗 更新时间:2023-10-30 00:00:31 26 4
gpt4 key购买 nike

我在 Web 应用程序中使用 ASP.NET MVC 和 JQueryMobile。我想生成一个链接:

<a href="/Whatever/Previous" data-role="button" data-icon="arrow-l">Previous</a>

我有一个辅助扩展方法可以让我这样做:

<%= Html.ActionLink<WhateverController>(c => c.Previous(), 
"Previous",
new { data-role = "button", data-icon="arrow-l" } ) %>

除了 data-roledata-icon 在 C# 中作为属性名称是无效的。使用 @data-role 也不起作用。

有什么语法可以解决这个问题吗?还是我坚持创建一个知道正确属性名称的更专业的助手。

最佳答案

您应该能够使用 IDictionary<string, object>而不是匿名对象:

Html.ActionLink<WhateverController>(c => c.Previous(), 
"Previous",
new Dictionary<string, object>
{
{ "data-role", "button" },
{ "data-icon", "arrow-l"}
})

关于c# - 如何在名称中指定带有 - 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4174311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com