new MVC project,
File > New > Project > MVC 4 project.
1- Select ASPX instead of RAZOR Syntax,
2- Remove all of Other Content of Directories
— How to add Controller and return string, Which URL
>> Add new Controller !!! url localhost/ControllerNAME/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
namespace Mvc4SoftwareProject.Controllers { public class mainController : Controller { // GET: /main/ !!!!!!!!>> localhost/main/ public string Index() { return "mainController>Index> Returned String. !"; } public ActionResult Index2() { return View(); } public ActionResult login() { return View("login"); } } } |
– How MVC calling controller, ?
Global.asax Fil e calling route table, after route table calling controllers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
namespace Mvc4SoftwareProject { // 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); BundleConfig.RegisterBundles(BundleTable.Bundles); } } } |
Route Config.cs > Called by Global.asax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace Mvc4SoftwareProject { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } } |