我建立使用MVC阿贾克斯佣工一个Ajax形式:http://msdn.microsoft.com/en-us/library/dd505013.aspx从ViewData的MVC中HtmlHelpers扩展对象
的代码类似于:
Ajax.BeginForm("ActionName", "ControllerName",
new {
SomeProperty = (ViewData["SomeObject"] as SomeClass).SomeProperty,
AnotherProperty = (ViewData["SomeObject"] as SomeClass).AnotherProperty,
AllTheProperties = (ViewData["SomeObject"] as SomeClass).AllTheProperties,
otherProperty= ViewData["otherObject"]
},
new AjaxOptions {},
new {id = "anHtmlId"});
,但有很多更多的属性在ViewData["SomeObject"]
虽然。
我想用尽可能少的线路尽可能增加ViewData["otherObject"]
到的RouteData对象只是,不希望拥有所有的someObject
奠定了独立,这样我可以将属性添加到它的性能,而无需再重温这段代码风景。
实质上是“合并”这些对象,因为routeData参数是有用的。
更新:一个想法:
Ajax.BeginForm("ActionName", "ControllerName",
ViewData["SomeObject"].addThePropertiesOf(ViewData["otherObject"]),
new AjaxOptions {},
new {id = "anHtmlId"});
凡addThePropertiesOf()
返回一个新的合并对象。我不想使用昂贵的反射镜片,否则这看起来不算高效。
听起来有点像AutoMapper可能做的事情。 –
Automapper看起来就像一把大锤放在指甲上,用来渲染视图。 – StuperUser
一方面,是的,另一方面也许'otherObject'是'someObject'的一个属性,你只是想使用现有的库来压扁这个东西,并从'someObject'中取出你不想要的属性。 –