views:

17

answers:

1

I an ASP.NET MVC we can pass some data via a ViewData and then show it on a page:

<%: ViewData["Foo"]%>

But how to make a hyperlink out of it?

Something like following:

<%: Html.ActionLink(ViewData["Foo"], "Index", "Home") %>
+1  A: 

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).

Yakimych
Thanks, it works! I'll pay attention to your remark about ViewData vs ViewModel. +1
rem