Saturday 21 January 2017

mvc 1



//~/App_start/RouteConfig

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

namespace model2
{
    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 = "Student", action = "Redirect", id = UrlParameter.Optional }
            );
        }
    }
}

-------------------------------------------------------------------------
//~/Controllers/StudentController

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

namespace model2.Controllers
{
    public class StudentController : Controller
    {
        // GET: Student
        //public ActionResult Index()
        //{
        //    return View();
        //}

        public ActionResult Default()
        {
            return Content("Hi there!");
        }

        public ActionResult Display()
        {
            return Json(new { Id = "a", FirstName = "b", LastName = "c", Phone = "d" }, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Redirect()
        {
            return RedirectToAction("Default");
        }

        
    }
}



No comments:

Post a Comment