I started doing a project from scratch using MVC 4 of VS 2012. As I opted for an empty, I can not start the view. I made the route:
routes.MapRoute(
name: "Operador",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Operador", action = "Index", id = UrlParameter.Optional }
);
But when I give an F5, it gives me this error:
Erro de Servidor no Aplicativo '/'.
Não é possível encontrar o recurso.
Descrição: HTTP 404. O recurso que você está procurando (ou uma de suas dependências) não pôde ser removido, seu nome foi alterado ou está temporariamente indisponível. Examine o URL e certifique-se de que está digitado corretamente.
URL solicitada: /
Informações sobre a Versão: Microsoft .NET Framework Versão:4.0.30319; Versão do ASP.NET:4.0.30319.34249
In my URL that is: http://localhost:60975/
I add after the slash (/) the controller name and still giving me error that did not find the view index. How do I resolve this?
public class OperadorController : Controller
{
//
// GET: /Operador/
public ActionResult Index()
{
return View();
}
}
View
@{
ViewBag.Title = "Operador";
}
<h2>Operador</h2>
Package.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="4.0.4" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="4.5.6" targetFramework="net45" />
</packages>
Global.asax
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
Route.config
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Operador",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Operador", action = "Index", id = UrlParameter.Optional }
);
}
}