Is there a shorter version of the following:
Using ASP.NET MVC, this is in the HTML page
<%= IsTrue ? Html.Image("~/images/myimage.gif") : "" %>
I know I'm only really writing 3 extra characters, just wondering if there is something better.
Is there a shorter version of the following:
Using ASP.NET MVC, this is in the HTML page
<%= IsTrue ? Html.Image("~/images/myimage.gif") : "" %>
I know I'm only really writing 3 extra characters, just wondering if there is something better.
No there is not, the ? operator is itself a short hand for the if else statement.
Not for the case you outlined.
If you are doing a null check on A
you could write var b = A ?? string.Empty;
Kindness,
Dan
It might be acceptable to create html helper:
public static string ImageIf(this HtmlHelper helper, condition, url){
return condition ? helper.Image(url) : "";
}
usage:
<%= Html.ImageIf(IsTrue, "~/images/myimage.gif") %>