-1

I am trying to handle a button event and redirect the application to a specific page (http://localhost:51443/Views/Shared/Error.cshtml), but while executing the line RedirectResult("~/Views/Shared/Error.cshtml") I am getting the exception as

Error from the application:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Views/Shared/Error.cshtml

While browsing the page I am getting the same exception. Can anyone advise how to handle this redirection error, previously in aspx using HttpResponse I would be able to redirect without any issue.

  • 1
    MVC works by calling action methods in controllers, not by calling views. –  Sep 25 '17 at 08:02

1 Answers1

1

Right click on your project name and add a html page. Copy paste your codes from Error.cshtml to the new html page. Redirect to that new html page instead.

  • Did the method work? I remember encountering an error somewhat the same as yours and solved it. –  Sep 25 '17 at 08:34
  • Nope it did not work, (http://localhost:51443/Shared/Testing) this is another CSHTML file I added while viewing in page inspector I am not able to view it still, I am using VS web express 2012. – Arvind Raj V Sep 26 '17 at 05:58
  • But it is visible when i directly navigate from it through the View("Testing") function. – Arvind Raj V Sep 26 '17 at 06:06
  • I used VS 2017 version. I mean create a html page by clicking on the project name and adding from there. Don't create a cshtml page under views/shared. For my project, i had to use a button such that when the button is clicked, the details in my html page will be displayed when i run the application. To do that, these are my codes: `function btnClick_retrieveApi() { location.href = 'NewPage.html' }`. See if this would be relevant to you. Hope it helps. –  Sep 26 '17 at 07:24
  • Or you can refer to: https://stackoverflow.com/questions/6211911/cant-get-defaultredirect-to-work?rq=1 –  Sep 26 '17 at 08:08