If I have the following controller action...
public void DoSomething() { }
will the framework actually convert it to this?
public EmptyResult DoSomething() { return new EmptyResult(); }
A controller that returns void will produce an EmptyResult. OK, so it's using a Null Object Pattern.
There is nothing like a VOID ActionResult (Action Method), hence ASP.Net MVC has created a class EmptyResult whose object is returned in case when NULL value or Nothing needs to be returned from Controller to View in ASP.Net MVC Razor.
The action method can return primitive type like int, string or complex type like List etc.
Yes
A controller that returns void will produce an EmptyResult.
Taken from
The Life And Times of an ASP.NET MVC Controller
Seems so, check the source code of ControllerActionInvoker.cs. I haven't verified it, but logic tells me that a void return will set actionReturnValue to null, so an EmptyResult is generated. This is the most recent source code, haven't checked the source for ASP.net MVC 1.0.
protected virtual ActionResult CreateActionResult(ControllerContext controllerContext, ActionDescriptor actionDescriptor, object actionReturnValue) { if (actionReturnValue == null) { return new EmptyResult(); } ActionResult actionResult = (actionReturnValue as ActionResult) ?? new ContentResult { Content = Convert.ToString(actionReturnValue, CultureInfo.InvariantCulture) }; return actionResult; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With