Controllers, strong typed views and helper classes in mvc4 razor

Adding a Controller in mvc4 razor


Controllers: Classes that handle incoming requests to the application, retrieve model data, and then specify view templates that return a response to the client.

Let's begin by creating a controller class. In Solution Explorer, right-click the Controllers folder and then select Add Controller.

Name your new controller "DefaultController". Leave the default template as Empty controller and click Add.

Notice in Solution Explorer that a new file has been created named DefaultController.cs. The file is open in the IDE.
public class DefaultController : Controller
{
    //
    // GET: /Default/

    public ActionResult Index()
    {
        return View();
    }

}
Replace the contents of the file with the following code.

public ActionResult Index()
{
    ViewBag.Message = "Hello ! <b>World</b>";

    return View();
}


Now Add new controller
Controllers, strong typed views and helper classes in mvc4 razor Controllers, strong typed views and helper classes in mvc4 razor Reviewed by Bhaumik Patel on 11:17 PM Rating: 5