mvc view without controller

I have searched on Google about creating view without controller but most of them shown me I can do it using redirect so I try out.

the result is because the app redirect so many time n it ends up it time out or generate error message.

if you have the same situation please show me how to handle this.

the reasons we don't want to use controller is because we will create many landing page from our web designer. and there is no need to generate any model, but we do want to use cshtml to do some server side work.

thanks
LVL 1
ITsolutionWizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelvin McDanielSr. DeveloperCommented:
I couldn't believe it when I saw it, but it does work.  Abhimanyu K Vatsa wrote an article about this in 2013; it provides exactly what we need to make this happen.

In his article we discover that there are two things we need to do:
1. Override HandleUnknownAction() in the controller that will provide the route to the "orphaned" Views.
2. Add the "orphaned" views to the /Views folder for the controller overridden in #1 above

I chose to override the Home controller because it was already there. I simply added the following block of code to the otherwise untouched HomeController.cs:
protected override void HandleUnknownAction(string actionName)
{
	this.View(actionName).ExecuteResult(this.ControllerContext);
}

Open in new window

Then I added three views to the /Views/Home folder.

After that, standard links such as the following will work as expected.
<div class="row">
	<div class="col-md-4">
		<p><a class="btn btn-default" href="/Home/One">Go to View #1 &raquo;</a></p>
	</div>
	<div class="col-md-4">
		<p><a class="btn btn-default" href="/Home/Two">Go to View #2 &raquo;</a></p>
	</div>
	<div class="col-md-4">
		<p><a class="btn btn-default" href="/Home/Three">Go to View #3 &raquo;</a></p>
	</div>
</div>

Open in new window


To verify that this works (six years later!) I created a .NET Standard 4.7.1 MVC solution using Visual Studio 2017.
I couldn't attach the file directly to this answer so I've shared it via my OneDrive.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kaufmed   ( ͡° ͜ʖ ͡°)*whispers*  I C# people.Commented:
Just out of curiosity, why would you want to do this? It would seem to be a non-standard way of doing things in MVC, and it could lead to confusion for the maintainer of the code in the future. Your controller doesn't need to do a crazy amount of work. It can simply return the view instances, like what you see in the sample code of a new MVC project.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET MVC

From novice to tech pro — start learning today.