Types of Action Result in MVC
ActionResult | Helper Method | Description |
ViewResult | View | Renders a view as a web page |
PartialViewResult | PartialView | Section of a view,that can be rendered inside another view |
RedirectResult | Redirect | Redirect to another action method |
RedirectToRouteResult | RedirectToRoute | Redirect to another action method |
ContentResult | Content | Returns a user-defined content type |
JsonResult | Json | Retuns a serialized JSON object |
JavaScriptResult | JavaScript | Returns a script that can be executed on the client |
FileResult | File | Returns a binary output to write to the response |
EmptyResult | (None) | returns a null result |
public ActionResult About()
{
return View();
}
public class SampleController : Controller
{
//
// GET: /Sample/
public ActionResult Index()
{
return Content("Hello from Index action in Sample Controller");
}
public ActionResult Verify(string username = "all")
{
return Content("Hello from Verify action in Sample Controller");
}
}
public ActionResult Index()
{
return Content("Hello from Home Controller");//Our content to render on the browser
public ActionResult Index()
{
// Redirect to Verify action inside the Sample Controller
return RedirectToAction("Verify", "Sample");
}
public ActionResult Index()
{
return RedirectToRoute("sample"); //Return to sample controller
public ActionResult Index()
{
return File("Web.config", "text/html"); //Return to file insie the web.config
}
public ActionResult Index()
{
return Json("hello from JSON","text/html", JsonRequestBehavior.AllowGet);
}
Note :This is for my personal use and content has been taken form various site...
Comments