In this quick article you will learn how a view can be rendered without its native Controller Action method.
Why do we need this?
Let's look at the following image.
In the image above, you can see that for each view we have a matching controller action. Each of these actions contains a single line of code. In fact, each of these actions contains exactly the same line of code. And this is completely unnecessary. Imagine what you will do when you have hundreds or thousands of views. Will you create hundreds or thousands of controller actions? Of course not, then how can we fix it?
In the MVC Framework, the controller class includes a method, HandleUnknownAction(), that executes whenever we attempt to invoke an action (or when we request a view that has no matching action method) on a controller that does not exist.
Now we are taking advantage of the HandleUnknownAction() method to render views even when a corresponding controller method does not exist.
In the image above you can see we don't have Post5.cshtml, so when I tried to access the Post5.cshtml view, it shows the following error.
To fix this issue, we can use a simple try-catch block and redirect the user on a PageNotFound view; here's how.
Hope this helps.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Jaima JosephPosted Jan 28, 2014, 4:41 AM
Hi, Abhimanyu, I have a doubt ,can we send view data to controller without clicking a button or link? I am trying to send data to controller using an ajax script on onblur event of my textbox. But it is not working.Is that possible?
Shivanand ArurPosted Sep 10, 2013, 6:47 AM
Nice 1