Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I'm new to ASP.NET. I am wondering how to redirect to an 'index.cshtml' page in ASP.NET. Please help!

What I have tried:

C#
Response.Redirect("index.cshtml");
Posted
Updated 6-May-22 4:27am
v2
Comments
Bryian Tan 25-Sep-17 12:31pm    
Is the web application using MVC architectural pattern? If that the case, do something like

Response.Redirect("~/ControllerName/ActionName");
Nalini123456 25-Sep-17 12:40pm    
I am trying to redirect the nav tab in bootsrtap to the index.cshtml page. So here is my code for the nav tab:

Inventory Module
Add Inventory
<a data-toggle="pill" href="Response.Redirect("~/ControllerName/ActionName");"List

The redirection will be based on the project structure you are using.

NORMAL ASP.NET
If you are not using any area's concepts then just Response.Redirect("Yourpage.aspx")

MVC - WITH AREAS Concept
<a href="@Url.Action(&amp;quot;Controller/ActionMethod&amp;quot;)" title="Modules">

MVC - WITH AREAS Concept
</a><a href="@Url.Action(&quot;Areas/Controller/ActionMethod&quot;)" title="Modules">

MVC - WITH AREAS Concept and T4MVC
</a><a href="@Url.Action(MVC.AreaName.Controller.ActionMethod())" title="Modules">


If you could'nt resolve this even after the above help, the easiest way is to use the developers tools in chrome.

Press F12, Go to Network and then click the button you will see the 404 error and the network URL in that.

The developerstools in chrome will help you out in finding where the issue is


https://developer.chrome.com/devtools/images/networkanel.png - Sample image

Check how it is trying to access and then proceed from there.

My 1st suggestion is kindly install the T4MVC from the nuget pakages and start using that to avoid these problems.
 
Share this answer
 
v2
Comments
Vaidhya.P 26-Sep-17 3:38am    
Kindly let me know if the above answer is not supporting you.
<a data-toggle="pill" href="@Url.Action("ActionName", "ControllerName")>List</a>


Leave the "Controller" suffix off the controller name, so if the class is called HomeController you use just "Home" as the controller name.
 
Share this answer
 
Ok here is the solution if anyone is having the same problem
just remove the data-toggle="pill" and it works fine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900