开发者

ViewData as a hyperlink

开发者 https://www.devze.com 2023-01-22 18:10 出处:网络
I an ASP.NET MVC we can pass some data via a ViewData and then 开发者_如何学Goshow it on a page:

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

精彩评论

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