检测动作调用者

时间:2012-05-31 09:33:16

标签: asp.net-mvc-3

我有Action返回局部视图。从不同的网页调用该部分视图。我需要在ResultForm Action中检测从哪个页面调用Action,最好的方法是什么?

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        public ActionResult ResultForm()
        {
            if (Request.IsAjaxRequest())
            {
                return PartialView("ResultForm"......);
            }

            return null;
        }

1 个答案:

答案 0 :(得分:0)

将其作为参数传递:

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "caller")]
public ActionResult ResultForm(string caller)

请注意缓存必须如何因此参数而异。在生成此操作的链接时,只需确保使用请求传递调用者参数。另一种可能性是在请求中使用UrlReferrer属性,但可能并不总是填充其值。