Modifying the Controller

Returning String from Controller

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

namespace Your_Web_Application_Name.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public string Index()
        {
            return "Hello MVC 5 Application";
        }
    }
}

Output

Hello MVC 5 Application


Application URL

http://localhost:xxxx

Passing Parameters from URL to Action Method

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

namespace Your_Web_Application_Name.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public string Index (string id,string name)
        {
            return "The value of Id = " + id + " and Name = " + name;
        }
    }
}

Output

The value of Id = 23 and Name = AIT


Application URL

https://localhost:44300/Home/index/23?name=AIT

Returning String from Controller

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

namespace  Enter_Your_Webapplication_Name.Controllers
{
    public class HomeController : Controller
    {
        public string Index(string id, string name)
        {
            return "Id = " + id + " , Name = " + Request.QueryString["name"];
        }
    }
}

Application URL

https://localhost:44300/Home/Index/23?name=AITAcadmy

Output

Id = 23 , Name = AITAcadmy