私はここでのパーティーに本当に遅れていることを知っていますが、これらは私にはまったく正しくないように思われたので、ここに私の2セントがあります:
public class PartialViewConverter : ViewResult
{
public ViewResultBase Res { get; set; }
public PartialViewConverter(ViewResultBase res) { Res = res; }
public override void ExecuteResult(ControllerContext context)
{
Res.ExecuteResult(context);
}
public static ViewResult Convert(ViewResultBase res)
{
return new PartialViewConverter(res);
}
}
使用法:
return PartialViewConverter.Convert(PartialView());
そして、ビューをオーバーライドする場合は、コントローラーで
protected override ViewResult View(string viewName, string masterName, object model)
{
//Whichever condition you like can go here
if (Request.QueryString["partial"] != null)
return PartialViewConverter.Convert(PartialView(viewName, model));
else
return base.View(viewName, masterName, model);
}
ビューを返すアクションメソッドは、要求されたときにパーシャルも自動的に返します。
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
//This will return a partial if partial=true is passed in the querystring.
return View();
}