I have on one of my views the following razor code:
@if (item.PMApproved != true) {
A helper could help:
public static class HtmlExtensions
{
public static IHtmlString ApproveButton(this HtmlHelper htmlHelper, MyViewModel item)
{
var button = new TagBuilder("input");
button.Attributes["type"] = "button";
button.Attributes["value"] = "Reset";
button.AddCssClass("btnresetinvoice");
button.AddCssClass("button");
button.Attributes["data-invoiceid"] = item.InvoiceId.ToString();
if (item.PMApproved)
{
button.Attributes["disabled"] = "disabled";
}
return new HtmlString(button.ToString(TagRenderMode.SelfClosing));
}
}
and then:
@Html.ApproveButton(item)
I don't know what language you're using, but you might be able to move your if
statement closer to the actual different between the two lines:
<input type="button" class="btnresetinvoice button" value="Reset"
data-invoiceid="@item.InvoiceId"
@{ if(item.PMApproved != true) {
@:disabled="disabled"
} }
/>