Asp.net mvc 3 MVC3 HTML扩展方法使用两个绑定,而不是通常的一个

Asp.net mvc 3 MVC3 HTML扩展方法使用两个绑定,而不是通常的一个,asp.net-mvc-3,extension-methods,Asp.net Mvc 3,Extension Methods,我正在尝试改进我的HTML扩展方法,以便可以绑定ID和值组件,以执行如下操作: @Html.AutoCompleteFor(model => model.Customer.ID, model => model.Customer.Name, "/Customer/Autocomplete") @Html.AutoCompleteFor(model => model.CustomerID, model => model.CustomerID_display, "/Custo

我正在尝试改进我的HTML扩展方法,以便可以绑定ID和值组件,以执行如下操作:

@Html.AutoCompleteFor(model => model.Customer.ID, model => model.Customer.Name, "/Customer/Autocomplete")
@Html.AutoCompleteFor(model => model.CustomerID, model => model.CustomerID_display, "/Customer/Autocomplete")
@Html.AutoCompleteFor(model => model.Customer.ID, model => model.Customer.Name, "/Customer/Autocomplete")
我现在是这样做的:

@Html.AutoCompleteFor(model => model.Customer.ID, model => model.Customer.Name, "/Customer/Autocomplete")
@Html.AutoCompleteFor(model => model.CustomerID, model => model.CustomerID_display, "/Customer/Autocomplete")
@Html.AutoCompleteFor(model => model.Customer.ID, model => model.Customer.Name, "/Customer/Autocomplete")
我需要扩展模型以包括CustomerID_显示,这有点笨重,需要非常具体的后期处理

我需要在显示值(实体的文本名称)上绑定的原因是,如果用户输入一个新项目,它可以被检测到并可能自动生成

当然,我期望的上述方法不起作用,我可能偏离了目标。但你应该知道我想做什么。如果我的上述预期方法有效,我的AutoCompleteFor实现将非常简单(现在每个人都在使用“平凡”这个词!)。我希望lambda会更有用,也许:

@Html.AutoCompleteFor(model => new AutoCompleteBinding { ID = model.Customer.ID, Name = model => model.Customer.Name }, "/Customer/Autocomplete")
谢谢

在HTML“…For”扩展中,通常只有一个表达式参数

 public static MvcHtmlString AutoCompleteFor<TModel, TValue>(
           this HtmlHelper<TModel> htmlHelper,
           Expression<Func<TModel, TValue>> expression,
           object postingTextBoxHtmlAttributes,
            string extraArguments,
            string sourceURL
           )
        {
              //...
        }