您的代碼:
@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說,這就是 '會話',「大廳「,」時間表「均爲查詢參數,則代碼應爲:
@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)
否則,如果你想在「會話」,「館」,「時間表」作爲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
)
你必須選擇其中之一。即發送參數'routeValues'和'htmlAttributes'作爲匿名對象(第一個),或者作爲'routeValues'的類型對象'RouteValueDictionary','htmlAttributes'發送'IDictionary<string, Object>
'。您的代碼與第一個代碼匹配,這就是爲什麼IDictionary<string, Object>
類型的'htmlAttributes'被視爲Object並生成不正確的代碼的原因。
正確的代碼應該是:
@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
})
或者
@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}
})
你能告訴我們什麼結果你希望它是什麼? – Silvermind 2012-04-15 17:49:34
我想他想要生成與會話,大廳和客戶端變量設置 - > Tommy 2012-04-15 18:20:54
@Tommy:對於延遲答案抱歉。我更新了問題。請看。 – user348173 2012-04-16 03:58:02