我如何判断 RenderAction 是否正在调用我的操作?
我有一个可能通过普通链接调用的操作,在这种情况下我会返回一个 View(),或者它也可以通过 AJAX 或 RenderAction (即作为子操作)调用,在这种情况下我会返回一个 PartialView()。
整理 AJAX 部分很容易 - 但如何测试我的操作是否被呈现为子操作?
理想情况下,我希望能够编写这样的代码:
if (Request.IsAjaxRequest() || Request.IsChildAction())
return PartialView();
return View();
显然 Request.IsChildAction() 不存在 - 是否有类似的东西,或者我只需要创建一个始终返回 PartialView 的特殊 ChildAction ?
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 Action) in which case I'd return a PartialView().
Sorting out the AJAX part is easy - but how can I test if my action is being rendered as a Child Action?
Ideally, I'd like to be able to write code like this:
if (Request.IsAjaxRequest() || Request.IsChildAction())
return PartialView();
return View();
Obviously the Request.IsChildAction() does not exist - is there something simlilar, or do I just need to create a special ChildAction that always returns a PartialView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你就快到了:
You were almost there: