locked
Improved MVC architecture RRS feed

  • Question

  • I have a question about url in MVC architecture of VS. I want when i access to param where HomeController(Default) and Index action(default) then instead of localhost:port/home/index/value-of-param -------> localhost:port/value-of-param and when i access to param where OtherController(any controller) and Index action(action default of OtherController) then instead of  localhost:port/other/index/value-of-param--------> localhost:port/other/value-of-param.

    For example: 

    :::::::: localhost:port/12/ or localhost:port/title-article-example/

    When i using: 

    namespace MvcApplication.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                if (RouteData.Values["id"] != null)
                {
                    string id = RouteData.Values["id"].ToString();
                    ViewBag.id = id;
                }
                return View();
            }
        }
    }

    //Result: ViewBag.id or id = 12 or title-article-example

    :::::::: localhost:port/article/12/ or localhost:port/article/title-article-example/

    When i using:

    namespace MvcApplication.Controllers
    {
        public class ArticleController : Controller
        {
            public ActionResult Index()
            {
                if (RouteData.Values["id"] != null)
                {
                    string id = RouteData.Values["id"].ToString();
                    ViewBag.id = id;
                }
                return View();
            }
        }
    }

    //Result: ViewBag.id or id = 12 or title-article-example

    AND I WANT A ARCHITECTURE MVC MULTI MODULE.

    for example: my application include: admin module and default module. 

    URL:

    - localhost:port/admin/home/index

    - localhost:port/default/home/index 

    -default:  localhost:port/ when access to index action of home controller of default module. 

    Thank!

    Saturday, March 31, 2012 2:52 AM