Gregorio Meraz Jr.
Gregorio Meraz Jr.

Reputation: 146

Changing Default Route on MVC 4

im trying to change the route of my solution to make it start with the controller that is called "formulariocontroller" and the action "formulario", i already looked up some tutorials here and questions and i thought i was doing it right but i cant make it work, its gives me this:

enter image description here

here is the code of my RouteConfig.cs

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

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

            routes.MapRoute(
                "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters*
        new
        {controller = "FormularioController",action = "Formulario",id = UrlParameter.Optional}
            );
        }
    }
}

and of my controller:

 using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        [HttpGet]
        public ActionResult Formulario()
        {
            ViewBag.Message = "Modifique esta plantilla para poner en marcha su aplicación ASP.NET MVC.";

            return View();

        }
        [HttpPost]
        public ActionResult Formulario(string text)
        {

            Session["Text"] = text;
            return RedirectToAction("Exito", "Home");
        }

        public ActionResult Exito()
        {


            ViewBag.Message = Session["Text"];

            return View();
        }


    }
}

any ideas?

Upvotes: 2

Views: 851

Answers (2)

Gregorio Meraz Jr.
Gregorio Meraz Jr.

Reputation: 146

ok, i solved it, i change the folder "home" name to "formulario" and it worked, this was the folder where the views were located.

noob mistake.

enter image description here

Upvotes: 0

Ankush Jain
Ankush Jain

Reputation: 7079

try this

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

            routes.MapRoute(
                "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters*
        new
        {controller = "Formulario",action = "Formulario",id = UrlParameter.Optional}
            );
        }

Change the name of controller to Formulario from FormularioController

Upvotes: 2

Related Questions