I have a controller named as UserController and in that only Index action is being called
another action added like as 'home action' is not being called and either calling actionresult/string or returning view
I am getting this error
while running at Google Chrome
{"Message":"No HTTP resource was found that matches the request URI
/user/home'.","MessageDetail":"No type was found that matches the
controller named 'home'."}
And running at Mozilla Firefox
Whoops! The page could not be found. Try giving it another chance
below.
Here is my whole Controller Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Mvc4Application1.Controllers
{
public class UserController : Controller
{
//
// GET: /User/
public ActionResult Index()
{
return View();
}
public ActionResult AddPlace()
{
return View();
}
public ActionResult UpdatePlace()
{
return View();
}
public ActionResult DeletePlace()
{
return View();
}
}
}
Here is RouteConfig.cs file
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{ controller = "Home", action = "Index",
id=UrlParameter.Optional }
Best Answer
A method in a Controller that returns a
string
will not be routable. It must return anActionResult
(or one of it's derived classes).Change it to:
Then in your Views/Home folder, add a view called Home that has something like: