I am rather new to Razor development. I want to set the disabled status of an input field based on a condition. So far, I have implemented the following:
<input type="text" class="form-control text-uppercase"
asp-for="CustInfo.ORG_ID"
disabled="@(Model.RecMode == (short)RecModeId.Update ? "disabled" : null)" />
I want to improve the above implementation by doing something like the article:
https://www.codeproject.com/Tips/670129/Enable-Disable-controls-on-a-web-page-using-MVC-Ra
I have:
namespace Demo.AppExtensions
{
public static class DisableHtmlControlExtension
{
public static IHtmlContent DisableIf(this HtmlString htmlString, Func<bool> expression)
{
if (expression.Invoke())
{
var html = htmlString.ToString();
const string disabled = "\"disabled\"";
html = html.Insert(html.IndexOf(">",
StringComparison.Ordinal), " disabled= " + disabled);
return new HtmlString(html);
}
return htmlString;
}
}
}
When I tried to use it in a razor page, I have this error:
It seems like I didn't reference to the extension correctly. Any advice?