Asp.Net MVC - redirect to same page without passing parameter

erw13n

I'm trying to redirect in same Index page that do multiple actions.

The problem is when in Index page with id parameter "http://example.com/Student/Index/1" Url.Action("Index") or Html.ActionLink("Index") will always generate : "http://example.com/Student/Index/1" instead of "http://example.com/Student"

This happen on Menu and Breadcrumb.

Controller :

public ActionResult Index(int? id)
{
   if (id == null) {
      // Show List
   } else if (id <= 0) {
      // Show Create Form
   } else {
      //Show Edit Form
   }
}

Is there any way to redirect to same page without parameter on View?

user3559349

You can set the route value to an empty string

@Html.ActionLink("Link text", "Index", new { id = "" })

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Passing custom parameter in custom attribute - ASP.NET MVC

ASP MVC redirect to error page from controller

ASP.NET Passing Parameter in URL

ASP.Net MVC Passing value to controller without dedicated button

how to replace space with hyphen '-' in asp.net Url routing while passing parameter from html (.aspx) page

ASP.NET GridView passing parameter

how to redirect to global error page if the user entered wrong page name or wring parameter in asp.net

ASP.NET Dropdown list passing parameter to next page

Asp.net mvc Redirect to same page after login

ASP.NET MVC show result without refreshing page

ASP.NET MVC 3 Redirect Requests to Root Page

MVC Post Form using Ajax (from partial view) but without any redirect (remain on same main view page)

Passing ID from Browser Tab/Window/Page to Server (ASP.NET MVC)

passing javascript parameter to asp.net

Redirect a page without a particular parameter Java JSP

Rails - redirect to show page passing a parameter

ASP.NET MVC Redirect to target page or redirect to previous page after login

passing several parameters through url to the same page in ASP MVC & Javascript

Redirect Page based on dropdown information in ASp.NET mvc

Open any url in popup and redirect current page in ASP.net without any button click on page load

Asp.net MVC Access Custom Error Page Without Authorization

How can I get value of EditorFor in ASP.Net Mvc and passing value in a button as parameter

Redirect to "You Are Forbidden" page without changing URL ASP.NET MVC

ASP.NET MVC SqlException does not redirect to error page

Redirect to error page from ajax call in ASP.net MVC

Passing parameter with slash (/) changing navbar menu item html link also in ASP.NET Core MVC

Redirect to page OnActionExecuting method ASP.NET Core 5 MVC

ASP.NET Core MVC : passing one parameter (from ViewModel) from view to controller

ASP.NET Core MVC: Passing one parameter from a view to a controller