你的代码:
@Html.ActionLink(string.Format("{0:HH\\:mm}", schedule.RecurrenceStart), "EventOverview", "BaseEvent",
new { id = schedule.BaseEvent.OID, type = schedule.BaseEvent.XPObjectType},
new Dictionary<string, object>
{
{"session", schedule.SessionId},
{"hall",schedule.HallId},
{"client",schedule.BasePlace.PremieraClientId}
})
如果您的意图是像@Tommy 所说的那样生成一个链接,即 'session'、'hall'、'schedule' 作为 queryStirng 参数,那么代码应该是:
@Html.ActionLink(string.Format("{0:HH\\:mm}", "schedule.RecurrenceStart"), "EventOverview", "BaseEvent",
new { id = schedule.BaseEvent.OID, type = schedule.BaseEvent.XPObjectType,
session= schedule.SessionId, hall =schedule.HallId, client =schedule.BasePlace.PremieraClientId},
null)
否则,如果您希望将 'session'、'hall'、'schedule' 作为 html 属性(根据您给定的代码),则有两个匹配的ActionLink方法签名:
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
string controllerName,
Object routeValues,
Object htmlAttributes
)
和
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
string controllerName,
RouteValueDictionary routeValues,
IDictionary<string, Object> htmlAttributes
)
You have to choose one of them. That is send both parameters 'routeValues' and 'htmlAttributes' as anonymous object (1st one) or as typed object, 'RouteValueDictionary' for 'routeValues' and 'IDictionary<string, Object>
' for 'htmlAttributes'. Your given code matched the 1st one, that is why the 'htmlAttributes' of type IDictionary<string, Object>
treat as Object and generating the incorrect tag.
Correct code should be:
@Html.ActionLink(linkText: string.Format("{0:HH\\:mm}", "schedule.RecurrenceStart"), actionName: "EventOverview", controllerName: "BaseEvent",
routeValues: new { id = schedule.BaseEvent.OID, type = schedule.BaseEvent.XPObjectType },
htmlAttributes: new
{
session = schedule.SessionId,
hall = schedule.HallId,
client = schedule.BasePlace.PremieraClientId
} )
Or
@Html.ActionLink(string.Format("{0:HH\\:mm}", "schedule.RecurrenceStart"), "EventOverview", "BaseEvent",
new RouteValueDictionary(new { id = schedule.BaseEvent.OID, type = schedule.BaseEvent.XPObjectType }),
new Dictionary<string, object>
{
{"session", schedule.SessionId},
{"hall", schedule.HallId},
{"client", schedule.BasePlace.PremieraClientId}
})