How can I tell if my action is being called by RenderAction?

前端 未结 1 2007
无人共我
无人共我 2021-02-13 12:49

I have an action that could potentially be called via a normal link, in which case I\'d return a View(), or it could also be called via AJAX or RenderAction (ie as a Child Actio

1条回答
  •  野的像风
    2021-02-13 12:55

    You were almost there:

    public ActionResult Foo()
    {
        if (Request.IsAjaxRequest() || ControllerContext.IsChildAction)
        {
            return PartialView();
        }
        return View();
    }
    

    0 讨论(0)
提交回复
热议问题