asp.net mvc - How to add a dynamic source to an image using MVC 3 (Razor) -


I am new to MVC and I have an image which can be correct or incorrect image by reply gives.

This is my current code:

  @if (Model.IsCorrect) {& lt; Img src = "@ Url.Content (@" ~ / content /images/Default_Correct.png ")" alt = "true" /> } Else {& lt; Img src = "@ Url.Content (@" ~ / content / images / default_key.png ")" alt = "wrong" /> }   

It works perfectly but I think there should be a very cleaner / better way to do something like that.

< Public static class ImageExtensions {public static IHtmlString miezes (This is HtmlHelper html halper, Bull is correct) {var urlHelper = new UrlHelper (varicolor.ViewContext.RequestContext); Var IMG = New Tag Builder ("IMG"); if (True is) {img.Attributes ["alt"] = "true"; Img.Attributes ["src"] = urlHelper.Content ("~ / content / images / default_Correct.png");} other {img.Attributes ["Alt"] = "gull "Img.Attributes [" src "] = urlHelper.Content (" ~ / Content / Images / Default_Wrong.png ");} Return MvcHtmlString.Create (IMG.Testring (TagRenderMode.SelfClosing))}}

And just in your opinion:

  @ html.MyImage (Model.IsCorrect)    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

memcached - Django cache performance -

java : convert string value to int -