通过的OutputCache一个复杂的对象属性不同 [英] OutputCache varying by a complex object property

查看:258
本文介绍了通过的OutputCache一个复杂的对象属性不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有收到一个复杂的对象作为参数控制器的动作,我需要的OutputCache这个复杂对象的属性之一发生变化。这可能吗?怎么样?

I have a controller action that receives a complex object as a parameter, I need the OutputCache to vary by one of the properties of this complex object. Is this possible? How?

推荐答案

如果你有一个像

public class person{
 public string Name {get;set;}
 public string location {get;set;}
} 

和在(强类型)查看您有一个表单

and in the (strongly typed)view you have a form

 @model Person

 @Html.BeginForm(){
  @Html.TextBoxFor(x=>x.Name)
  @Html.TextBoxFor(x=>x.location)
 }

和提交表单到的ActionResult savePerson,像

and you submit the form to an ActionResult savePerson, with varying signature like

public ActionResult savePerson(Person p){
 // p.Name
 // p.location

}

public ActionResult savePerson(string Name, string location){

}

所以我如果你喜欢注释

therefore i think if you annotate the ActionResult like

[OutputCache(Duration=3600, VaryByParam="Name")]
public ActionResult savePerson(Person p)
{
    //
    return View();
}

它会为你做,或者如果你有一个像

it will do for you, or if you have a complex model like

public class person{
 public string Name {get;set;}
 public Location loc {get;set;}
} 
public class Location{
  public string address
}

尝试

[OutputCache(Duration=3600, VaryByParam="Person.Location.address")]
public ActionResult savePerson(Person p)
{
    //
    return View();
}

这篇关于通过的OutputCache一个复杂的对象属性不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆