我有一个 ASP.NET MVC3 站点,我需要在侧边栏中显示一些与帐户相关的统计信息
我在布局中有一个 RenderAction 即
@{ Html.RenderAction("GetStats", "MyController"); }
MyController 中的 action 方法返回一些文本
[HttpGet]
public ContentResult GetStats()
{
... snip (get stats from cache/db as the case may be)....
return Content(String.Format("Your stats: {0}", stats));
}
在正常情况下工作正常。
但是,假设视图包含一个表单,并且如果抛出服务器端模型验证错误,则渲染操作会返回一个 404 视图,该视图嵌入在应该是统计信息的位置。页面的其余部分显示正常,并带有正确的验证消息等。
我还尝试使用具有相同结果的常规局部视图而不是 ContentResult。