开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜