0

I'm trying to get the current page from view in controller, but the code throws the error shown below.

Home controller:

public ActionResult Index()
{
    // throws Null
    Page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;

    // throws error
    Page = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
    var model = DeviceLoginManager.GetOnlineDevices();

    return View(model);
}

Error:

Unable to cast object of type 'System.Web.Mvc.MvcHandler' to type 'System.Web.UI.Page in MVC controller

I need get same page or alternatives for System.Web.UI.Page in ASP.NET MVC.

enter image description here

5
  • 1
    System.Web.UI.Page is Webforms, not MVC. learn.microsoft.com/en-us/dotnet/api/… Commented Oct 18, 2024 at 8:15
  • need alternatives for Page 'HttpContext.Handler' as Page also using but it returns null Commented Oct 18, 2024 at 8:29
  • 1
    In ASP.NET MVC, you do not have pages - you have views. There's no alternative for the old ASP.NET webforms pages - you just cannot get that. The question really is more: WHY do you want to get a page? What are you trying to do with that page? Commented Oct 18, 2024 at 8:48
  • i need to pass in class library sdk method contains Page public void ExecuteCommand(System.Web.UI.Page page, XmlDocument request, DeviceResponseHandler responseHandler, ExceptionHandler responseExceptionHandler) {//work} Commented Oct 18, 2024 at 10:07
  • Is this class library something you wrote? It appears to have a hard dependency on Web Forms, and thus needs to be updated to not have that dependency. Commented Oct 18, 2024 at 14:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.