Types of Action Result in MVC



ActionResultHelper MethodDescription
ViewResultViewRenders a view as a web page
PartialViewResultPartialViewSection of a view,that can be rendered inside another view
RedirectResultRedirectRedirect to another action method
RedirectToRouteResultRedirectToRouteRedirect to another action method
ContentResultContentReturns a user-defined content type
JsonResultJsonRetuns a serialized JSON object
JavaScriptResultJavaScriptReturns a script that can be executed on the client
FileResultFileReturns 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

Popular posts from this blog

Prime Number Program in C#

Fibonacci Series in C#

Joins in SQL server