我试图改变我的解决方案的路线,使其从名为" formulariocontroller"的控制器开始。和动作" formulario",我已经在这里查找了一些教程和问题,我认为我做得对,但我不能让它工作,它给了我这个:
这是我的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}
);
}
}
}
和我的控制者:
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();
}
}
}
任何想法?
答案 0 :(得分:2)
试试这个
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}
);
}
将控制器的名称从Formulario
FormularioController
答案 1 :(得分:0)
noob错误。