0

Is there a way to get the content of a view between curly brackets in a html helper extension, so that I can either display the content or not depending a conditional element. The idea is to test if the user has access to specific content, if so then show inner content, if not then display nothing.

Something along the lines of the Html.BeginForm

<% using(Html.HasAccess()){%>
  <p>You can view the content<p>
<% } %>

I have found lots of examples where you can add tags around content, but none that manipulate the content directly.

Is it possible or is there another way?

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

1

Why not just:

<% if (Html.HasAccess()){%>
  <p>You can view the content<p>
<% } %>

?

Peter Porfy
  • 8,921
  • 3
  • 31
  • 41
  • I was trying to get a way from having lots of if statements all over the page, but I guess all I would be doing is having a lot of using statements all over the page instead. You right keep it simple. Thanks. – Peter Webb Sep 10 '12 at 14:45
  • You can always refactor/reorganize your view structure to make it cleaner if it feels messy (partial views, child actions, helpers), but that's a different topic. – Peter Porfy Sep 10 '12 at 14:49