强类型T4MVC动作/ ActionLink的 [英] Strongly-typed T4MVC Action/ActionLink

查看:169
本文介绍了强类型T4MVC动作/ ActionLink的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 T4MVC (FYI:v2.6.62)很长一段时间,我已经在我们的code被缓慢地移动到这样的工作(在魔弦少依赖)。

I've been using T4MVC (FYI: v2.6.62) for quite some time, and I've been slowly moving over our code to this way of working (less reliance on magic strings).

但我不得不停止,因为,出于某种原因,T4MVC无法对象转化为URL和似乎只能够在基本类型(int /字符串/等)工作。

But I've had to stop because, for some reason, T4MVC is unable to translate objects into urls, and only seems to be able to work on primitive types (int/string/etc).

下面是一个例子:

路线明细:

/MyController/MyAction/{Number}/{SomeText}

类:

namespace MyNamespace
{
  public class MyClass
  {
    public int Number { get; set; }
    public string SomeText { get; set; }
  }
}

控制器:

public class MyController
{
  public virtual ActionResult MyAction(MyClass myClass)
  {
    return View();
  }
}

查看:

<%= Html.Action(
  T4MVC.MyController.Actions.MyAction(
    new MyClass()
    {
      Number = 1,
      SomeText = "ABC"
    }
 ) %>

最终的结果是这样的:

The end result is this:

/MyController/MyAction?myClass=MyNamespace.MyClass

而不是

/MyController/MyAction/1/ABC

其他人是否有这个问题?是T4MVC网址,这样可用?

Does anyone else have this problem? Are T4MVC urls like this available?

问题还要求在 ASP.NET论坛

推荐答案

更新(2012年10月11日):最近增加了对型号Unbinders(见的商务部)应该有希望涵盖了很多的这些案件

Update (10/11/2012): the recently added support for Model Unbinders (see section 3.1 in the doc) should hopefully cover a lot of these cases.

原来的答复:

复制从论坛主题:

嗯,我不认为这又拿出了呢。也许在人们有采取对象,该对象的值来自提交的表单数据,而不是在URL上传递行动方法大多数情况下?在这种情况下,问题并不存在。

Hmmm, I don't think this has come up yet. Maybe in most cases that people have Action methods that take an object, the object's values come from posted form data, rather than being passed on the URL? In such scenario, the question doesn't arise.

我觉得理论上T4MVC可以改变支持这一点。它只是需要推广的所有对象的顶级属性,路由值,而不是尝试使用对象本身(显然,目前的行为是虚假的,并且是只调用toString()盲目的结果)。

I think in theory T4MVC could be changed to support this. It would just need to promote all the object's top level properties as route values rather than try to use the object itself (obviously, the current behavior is bogus, and is a result of just calling ToString() blindly).

有其他人碰到这一点,认为这是值得解决?

Have others run into this and think it's worth addressing?

这篇关于强类型T4MVC动作/ ActionLink的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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