PROCESSING, PLEASE WAIT
This website uses cookies to grant a better experience for visitors. By browsing, you acknowledge that you read and accept Terms of Use, Privacy and Cookie Policy.
Change Edition (Content might be different) :
MENU SEARCH
Home \ Solutions \ Solution Center \ Programming \ .NET MVC

How to make url definitions from Controller Actions in .NET MVC?

Posted On : Aug 20, 2020

This can be done at two steps; first, call the MapMvcAttributeRoutes function of "routes" variable derived from RouteCollection under the default function RegisterRoutes in the RouteConfig.cs to enable url routing via Actions, then configure the urls as you want in the Controllers like below.

Sample RouteConfig.cs file;

using System.Web.Mvc;
using System.Web.Routing;

namespace KaanCamur
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // We just call the MapMvcAttributeRoutes() function of "routes" variable derived from RouteCollection here, that's all. Other codes you see here are created by system as default.
            routes.MapMvcAttributeRoutes();

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Eng", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

Sample Controller.cs file;

using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;

namespace KaanCamur.Controllers
{
    public class EngController : Controller
    {
        // The "Index" Action will be triggered when requested "Eng/Home" url in address bar.
        [Route("Eng/Home")]
        public ActionResult Index()
        {
            return View()
        }

        // The "Contact" Action will be triggered when requested "Eng/Contact" url in address bar.
        [Route("Eng/Contact")]
        public ActionResult Contact()
        {
            return View()
        }

        // The "Products" Action will be triggered when requested "Eng/Products" url in address bar.
        [Route("Eng/Products")]
        public ActionResult Products()
        {
            return View()
        }

        // The "MyNotes" Action will be triggered when requested "Eng/Blog" url in address bar.
        [Route("Eng/Blog")]
        public ActionResult MyNotes()
        {
            return View()
        }
    }
}

1,571
6 (0 %)
This may be the post also your loved ones are looking for a long time. Share and inform them.
COMMENTS 0
No comment made yet. Make first via below form.

WRITE COMMENT

Do you have any comments, additional informations or corrections? Right here, write now!
Name
Avatar
Change
Restore DefaultClose (X)

E-Mail (Will not publish, you’ll get notification when your comment is published or replied.)
Website (Optional)
Comment
Your profile will be stored for this browser automatically.
QUICK LINKS


HIGHLIGHTS

LATEST POSTS
MOST LIKED
MOST COMMENTED
NEWS
REVIEWS
DIGITAL MARKETING
DESIGN

HTML
CSS
PHOTOSHOP
PROGRAMMING

C#
JAVASCRIPT/JQUERY
.NET MVC
SQL
FLIGHT SIMULATOR

FLIGHT SIMULATOR X (FSX)
FLIGHT SIMULATOR 2020
NOTES FROM LIFE

FOOTBALL
TRAVEL
SOLUTION CENTER

ALL SOLUTIONS
DESIGN
PROGRAMMING
DATABASE
HARDWARE
MS WINDOWS
MS OFFICE
WEB
DIGITAL MARKETING
INFO

ABOUT ME
CONTACT


Kaan Çamur HELLO, THIS IS KAAN ÇAMUR. I’VE SOME SKILLS ON COMPUTERS AND DIGITAL TECHNOLOGIES. I CREATED MY THIS DIGITAL HOME TO SHARE ALL MY EXPERIENCES WITH YOU. I BELIEVE YOU’LL FIND USEFUL CONTENTS HERE THAT WILL MAKE YOU HAPPY. IF YOU BE HAPPY, I WILL ALSO BE HAPPY. SO, LET ME KNOW YOU’RE HAPPY. :-)
WANT TO BE INFORMED WHEN THE NEW POST HAS ARRIVED?
E-MAIL  :  
OR FOLLOW

Copyright © 2024 Kaan Çamur. All rights reserved.

All materials and posts in this website are protected by copyright laws.

TERMS OF USEPRIVACYCOOKIE POLICYCONTACT