Hi 65sametkaya65,
You need to map new route in the RouteConfig file before the default one.
Refer below example.
RouteConfig
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "MyRoute",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASPSnippets.";
return View();
}
[HttpGet]
public ActionResult View(int? id)
{
ViewBag.Id = "Your Id is: " + id;
return View("Index");
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@if (ViewBag.Message != null)
{
@ViewBag.Message<br />
}
@if (ViewBag.Id == null)
{
@Html.ActionLink("View", "View", "Home", new { id = "1" }, null)
}
else
{
@ViewBag.Id
}
</div>
</body>
</html>
Screenshot