Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 附加到MVC HtmlHelper DropDownList原始选定值的匿名号码_Asp.net Mvc_Razor_Html Helper - Fatal编程技术网

Asp.net mvc 附加到MVC HtmlHelper DropDownList原始选定值的匿名号码

Asp.net mvc 附加到MVC HtmlHelper DropDownList原始选定值的匿名号码,asp.net-mvc,razor,html-helper,Asp.net Mvc,Razor,Html Helper,我有一个MVC razor视图,可以捕获用户的信用卡信息。CC expiration date的month属性限定为字节数组类型的selectlist private static readonly byte[] Months = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; public static SelectList GetMonthsSelectListthis HtmlHelper helper) { return ne

我有一个MVC razor视图,可以捕获用户的信用卡信息。CC expiration date的month属性限定为字节数组类型的selectlist

private static readonly byte[] Months = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
public static SelectList GetMonthsSelectListthis HtmlHelper helper)
    {
        return new SelectList(Months);
    }
月模型属性是使用自定义HtmlHelper DropDownList for extension呈现的-

@Html.DropDownListForWithDisplayNameAsOptionLabel(x => x.CardExpirationMonth, Html.GetMonthsSelectList(), new { @required = "required" })
这最终会调用标准的MVC html.DropDownListFor-

public static IHtmlString DropDownListForWithDisplayNameAsOptionLabel<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel,TProperty>> expression, IEnumerable<SelectListItem> selectListItems, object htmlAttributes = null)
    {
        var modelMetadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);
        return helper.DropDownListFor(expression, selectListItems, modelMetadata.GetDisplayName(), htmlAttributes);
    }
public static IHtmlString DropDownListForWithDisplayNameAsOptionLabel(此HtmlHelper帮助程序、表达式、IEnumerable selectListItems、对象htmlAttributes=null)
{
var modelMetadata=modelmetada.FromLambdaExpression(表达式,helper.ViewData);
return helper.DropDownListFor(表达式、selectListItems、modelMetadata.GetDisplayName()、htmlAttributes);
}
回发后,模型绑定器通常会选择1-12之间的值

然而,我们偶尔发现发送到支付网关的卡月份不在1-12之间。而是有一个额外的数字附加到实际选择的值上,导致事务失败

  • 选择11时,117通过
  • 选择5时,53通过
  • 选择9时,99通过
  • 该问题发生在生产过程中,影响了一小部分信用卡交易

    在回发时进行调试时,我总是从模型绑定器中找到正确的值。无法真正理解匿名数字是如何附加到原始选定值的


    感谢任何进一步调试该问题的指针。

    请检查SELECT的视图源。它是否呈现正确的选项值?是的,它确实具有所有选项值。正如我前面提到的,这是我正在尝试解决的零星行为;事务成功后..它可能会将旧值附加到当前值..@Ganesh,因此如果我理解正确,您的意思是model binder可能会将旧值附加到新值?而ModelState.Clear()只是一种确认这种情况不会发生的方法。。你能在控制台手表上交叉核对吗??