2

I've got this problem trying to use Html helpers. I've read that dynamical casting should work but I am not sure how to get it in my case. Code:

@{ 

 Html.LinkIfHasData(top.Text, Html.MenuTargetURL(top), false, 
 new { rel    = "tab" + @top.ID });

 }

LinkIfHasData returns MvcHtmlString and MenuTargetURL returns string.

I tried this:

@{ 

 (string)Html.LinkIfHasData(top.Text, (string)Html.MenuTargetURL(top), false, 
 new { rel    = "tab" + @top.ID });

 }

But it doesn't work. Any ideas?

Thank you,

H

bobek
  • 8,003
  • 8
  • 39
  • 75
  • This might help - http://stackoverflow.com/questions/4136703/razor-htmlhelper-extensions-not-found – Richard Dalton Oct 27 '11 at 15:26
  • I was dynamically creating a bool that I used in foreach loop. So instead of doing var IsLocal = ... I did bool? IsLocal = ... and now it works. – bobek Oct 27 '11 at 15:33

1 Answers1

2

You have inserted your helper within a code block, so the HTML generated will not go into your view. Remove the helper from the code block, and put it in-line in your view. Change your view as follows:

@Html.LinkIfHasData(top.Text, Html.MenuTargetURL(top), false, 
    new { rel    = "tab" + @top.ID })
counsellorben
  • 10,924
  • 3
  • 40
  • 38