Wednesday, 1 July 2015

What are the different types of Results in MVC (.Net)?

There are 11 different response types which can be sent to the end user :-

  1. ViewResult - Renders a specified view to the response stream
  2. PartialViewResult - Renders a specified partial view to the response stream
  3. EmptyResult - An empty response is returned
  4. RedirectResult - Performs an HTTP redirection to a specified URL
  5. RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data
  6. JsonResult - Serializes a given object to JSON format
  7. JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client
  8. ContentResult - Writes content to the response stream without requiring a view
  9. FileContentResult - Returns a file to the client
  10. FileStreamResult - Returns a file to the client, which is provided by a Stream
  11. FilePathResult - Returns a file to the client


Example:-

1. View Result: - 
              public ActionResult Home()
             {
                   return View();
              }
2. Partial View Result :-
            Public ActionResult AboutUs()
            {
                 return PartialView("Hi");
             }
3. Json Result :-
            Public ActionResult Home()
            {
                 return Json("hello from JSON");
            }

No comments:

Post a Comment