Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htmlHelper vs partial view

I can't decide whether I should use a htmlHelper or a partial view for solving my problem.

I would like to reuse the following code:

<div style="width: 500px; float: left;">
  <div class="box effect2">
    <span><a href="@Url.Action("someMethod", "somController")">
        <img src="@Url.Content("~someurl)" /></a></span>
  </div>
</div>

The href and the image source would be parameters.

What is the best way to do it ?

like image 871
Sam Avatar asked Feb 26 '13 13:02

Sam


1 Answers

Use partial view when you have lots of markup. Html helpers should be used to generate only small portions of HTML. In this particular case you are really on the limit and both approaches would be fine. Use the one you prefer for this particular example. I'd probably go with a custom HTML helper here as this seems quite a common widget that could be reused across various applications if you incorporate it into an assembly.

like image 90
Darin Dimitrov Avatar answered Sep 21 '22 13:09

Darin Dimitrov