tags:

views:

37

answers:

3

Hi I'm working with a project (asp.net mvc) where I need to show pictures on one site. They gone have jquery and be surrounded by a div like <div><img/></div>

I'm relatively new on MVC so I'm not sure what ways are the best to work in it yet. Should I do a ImageHelper so i can access it like <% Html.ImageJquery() %> or should i just do it plain in the view

what are your thoughts on this?

+1  A: 

I am not sure if there is any single best practice for this case. As you already said you could create an extension method on a HtmlHelper or just put the code in the view.

Because the "added" code is a very simple (just two divs) I would skip extension method and just add the divs in the view. But if the code is actually more complex I would create a helper.

Cheers!

rrejc
+1  A: 

It depends how often you would use the helper. If it is used in a couple of places it would make sense, because it helps you to reduce redundant code.

The other option you have are partials.

Malcolm Frexner
+1  A: 

I would go with an Extension method on the HTMLHelper , so that it accepts the 'src' value as a parameter and constructs the image tag accordingly.

Regarding Rendering of UI elements , i did read a blog post on 'Conditional Rendering' which i thought you would find it interesting .

please check the link below .

Conditional Rendering

Thanks , Vijay.

vijaysylvester
All good answers. thanks guys. I just mark one +1 on the rest
Dejan.S