asp.net mvc partials do they know if the are run stand alone or as part of a page
Does anyone know, if a partial view (PartialViewResult
) in an ascx file - knows if it is running stand alone - called directly from the browser or as part of a page.
I would like to treat these cases differently.
Edit:
Case 1: In the page case it could be that a page has a few partials that are loaded using ajax while the page is being built. The partials might be called again using ajax according to the users actions. In this case I consider them as controls on a page.开发者_JAVA百科Case 2:In the stand alone case the partial could be called as part of a test directly from the browser. In this case you only see the partial part in the browser.
Case 3:In the third case the partial could be called as part of an iframe within a google chrome extension (for example). In this case you can see the partial in a page that might not have been built in your web application.
Hope this makes sense.
Thanks in advance of for those whom it concerns - happy new year.
You could distinguish between normal requests and ajax requests (Request.IsAjaxRequest()
) and child actions (ControllerContext.IsChildAction
- rendered with Html.Action
).
As an alternative the controller action returning the partial view could set some model property indicating that the partial was rendered via this action instead of being directly included in a view with Html.RenderPartial
for example.
精彩评论