2

我正在使用Ajax.Actionlink来自 MVC 框架的,一切都适用于我的目标和部分视图。但是我已经看到 html 输出没有将“id”属性添加到结果<a href=""></a>标记中。

有什么办法可以添加吗?

4

3 回答 3

7

尝试其中一种重载,例如

public static string ActionLink(
    this AjaxHelper ajaxHelper,
    string linkText,
    string actionName,
    Object routeValues,
    AjaxOptions ajaxOptions,
    Object htmlAttributes
)

然后可以在htmlAttributes参数中指定id,例如

new { id = "myIdValue" }
于 2009-12-09T22:39:37.657 回答
3

您需要new { id = "myId" }在对象中使用 htmlAttributes 参数,该参数在其几个构造函数中可用。或者,您可以使用它的IDictionary<string, string>几个构造函数中也可用的 htmlAttributes 来填充它。

于 2009-12-09T22:34:56.703 回答
-2

我相信您正在寻找 routeValues 参数。

<%= Ajax.ActionLink("SomeAction", "SomeController", new { id = ID_HERE }, null) %>
于 2009-12-09T22:36:13.577 回答