T4MVC 模型绑定
我执行了以下操作:
public ActionResult GetCityObjects(string cityAlias)
由于某些原因,我添加了一个自定义 ModelBinder:
public ActionResult GetCityObjects(City city)
现在,当我将 city 参数传递给适当的 T4MVC 方法时,我想让 T4MVC 添加值为 city.Alias 的“cityAlias”参数。有什么办法可以实现吗?
I had the following Action:
public ActionResult GetCityObjects(string cityAlias)
By some reasons I added a custom ModelBinder:
public ActionResult GetCityObjects(City city)
Now I want to make T4MVC add "cityAlias" parameter with value city.Alias when I pass city parameter to appropriate T4MVC method. Is there any way to achieve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
现在可以使用 T4MVC 模型解绑器功能(http://t4mvc.codeplex.com/documentation 3.1),您可以为
City
类型实现自定义解绑定器,如下所示:然后在 T4MVC 中注册它(从 Application_Start ):
之后就可以正常使用 MVC.Home.GetCityObjects(city) 来生成 url 了。
It's now possible with T4MVC Model Unbinder feature (http://t4mvc.codeplex.com/documentation 3.1), you could implement custom unbinder for
City
type like that:and then register it in T4MVC (from Application_Start):
After that you can normally use MVC.Home.GetCityObjects(city) for generating urls.
我不这么认为。
您需要使用无参数版本并手动添加路由值:
如果您查看源代码,您会发现生成的方法只是使用参数名称“city”添加
city
实例。I don't think so.
You need to use the parameterless version and add route values manually:
If you look at the source code you will see that the generated method just adds
city
instance using parameter name 'city'.我找到了解决方法。我已将以下内容硬编码到 T4MVC:
我不能说我喜欢它,但至少它适用于我的情况。
David,您对将更通用的实现引入到 T4MVC 有何看法?
I have found a workaround. I have hardcoded the following to T4MVC:
I can't say I like it, but at least it works in my case.
David, what do you think about introducing a more general implementation of this into T4MVC?