Asp.Net MVC中不指定View Name时如何返回ActionResult的
通过ActionResult类查找它的子类,下面是找到的代码:
//ViewResultBase.cs
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
if (string.IsNullOrEmpty(this.ViewName))
this.ViewName = context.RouteData.GetRequiredString("action");
ViewEngineResult viewEngineResult = (ViewEngineResult) null;
if (this.View == null)
{
viewEngineResult = this.FindView(context);
this.View = viewEngineResult.View;
}
TextWriter output = context.HttpContext.Response.Output;
this.View.Render(new ViewContext(context, this.View, this.ViewData, this.TempData, output), output);
if (viewEngineResult == null)
return;
viewEngineResult.ViewEngine.ReleaseView(context, this.View);
}
这里可以看到如果View不指定会返回路由中action名相同的view