I have created Helper file that is not accessible from App_Code folder and also HtmlHelper is getting null while running. It was resolved by get helpers from the PageContext.
Creating Helper File:
public static MvcHtmlString GetExternalProfile(this HtmlHelper helper, int? userId)
{
models db = new models();
UserLogin userlogin =db.UserLogins.Find(userId);
string externalProfile =userlogin.DevName;
if (externalProfile == null)
{
externalProfile = "WebMaster";
}
return MvcHtmlString.Create(externalProfile.ToString());
}
View file in App_Code folder:
@using System.Web.Mvc.Html;
@using System.Web.Mvc
@helper SimpleHelper(int UserId)
{
var page = (WebViewPage)PageContext.Page;
var Html = page.Html;
@Html.GetExternalProfile(UserId);
}
Post your comments / questions
Recent Article
- How to check PAN-Aadhaar is Linked or NOT?
- How to customize pagination for django admin?
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)
- This action cannot be completed because the file is open in SQL Server(SQLEXPRESS) - FIXED
Related Article