Posts

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 Ve...

IEnumerable

An IEnumerable generic interface is returned from query expressions. A query expression that selects ints will be of type  Enumerable, IEnumerable<T> The only thing you want is to iterate over the elements in a collection. You only need read-only access to that collection. IEnumerable  interface contains an abstract member function called  GetEnumerator()  and return an interface IEnumerator  on any success call. This  IEnumerator  interface will allow us to iterate through any custom collection. any element in a collection can be retrieved through its index property. But instead of element index, the  IEnumerator  provides two abstract methods and a property to pull a particular element in a collection. And they are  Reset() ,  MoveNext()  and  Current . IEnumerable can move forward only over a collection, it can’t move backward and between the items. IEnumerable is best to query data from in-...