如果我有下面的控制器动作...
public void DoSomething()
{
}
框架真的会把它转换成这样吗?
public EmptyResult DoSomething()
{
return new EmptyResult();
}
发布于 2010-01-12 19:56:27
看起来是这样,检查一下source code of ControllerActionInvoker.cs。我还没有验证它,但是逻辑告诉我,一个空的返回值会将actionReturnValue设置为null,因此会生成一个EmptyResult。这是最新的源代码,还没有检查过ASP.net MVC1.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;
}
发布于 2010-01-12 19:54:50
它不会“转换”它,但对于用户而言,这两种方法的效果是一样的。将发送一个请求,但不会向客户端返回任何响应。
就我个人而言,我认为您需要向客户端发送一些响应,即使您只是直接向响应流编写了continue或success。即使是一个JSON,或者一个空的true
文档也比什么都没有要好。
https://stackoverflow.com/questions/2048643
复制相似问题