ViewData as a hyperlink
I an ASP.NET MVC we can pass some data via a ViewData
and then 开发者_如何学Goshow it on a page:
<%: ViewData["Foo"]%>
But how to make a hyperlink out of it?
Something like following:
<%: Html.ActionLink(ViewData["Foo"], "Index", "Home") %>
Cast it to string
:
Html.ActionLink((string)ViewData["Foo"], "Index", "Home")
In general, however, try to avoid using ViewData
and use a strongly typed ViewModel
instead. (Thus, you would have avoided the problem in this question, btw).
精彩评论