Empty Result in ASP.NET MVC

Empty Result in ASP.NET MVC

In this article, I am going to discuss Empty Result in the ASP.NET MVC application. Please read our previous article where we discussed ContentResult in ASP.NET MVC. ASP.NET MVC has different types of Action Results. Each action result returns a different format of the output. As a programmer, we need to use different action results to get the expected output. Action Results return the result to the view page for the given request. 

Empty Result in ASP.NET MVC

The ASP.NET MVC Framework wants us to use the EmptyResult when the action is specifically intended to return nothing. Unlike all of the previous ActionResults though, EmptyResult doesn’t have a helper. Additionally, if an action returns null, MVC will detect that and make it return an EmptyResult. Let’s Modify the Home Controller to use Empty Result as shown below

public class HomeController : Controller
{
    public EmptyResult Empty()
    {
        return new EmptyResult();
    }

    public ActionResult NothingReturned()
    {
        return null; //Returns an EmptyResult
    }
}

In the next article, I am going to discuss RedirectResult, RedirectToRoute, and RedirectToAction Results in ASP.NET MVC Application. Here, in this article, I try to explain Empty Result in ASP.NET MVC application with examples. I hope this article will help you with your need. I would like to have your feedback. Please post your feedback, question, or comments about this article. 

Leave a Reply

Your email address will not be published.