예제 #1
0
        /// <summary>
        /// 値が整数の場合の範囲指定パラメータのチェックとHTMLへの反映
        /// </summary>
        /// <param name="context"></param>
        private void CheckIntegerParameter(ClientModelValidationContext context)
        {
            // Minのチェックと設定
            if (Min != null)
            {
                // Minは整数以外はエラー
                //if(getNumberType(Min.GetType()) != RangeValueTypes.Integer) throw new VueServerException("範囲指定のバリデーションで整数の項目に整数以外の「Min」が設定されています。");

                // タグの属性[min]に最小値を設定
                context.Attributes["min"] = Min.ToString();

                // 最小値の異常メッセージが設定されている場合はタグの属性[min-error-message]に設定
                if (!string.IsNullOrEmpty(MinErrorMessage))
                {
                    context.Attributes["min-error-message"] = MinErrorMessage;
                }
            }

            // 最大値と最大値のエラーメッセージを設定
            if (Max != null)
            {
                // Minは整数以外はエラー
                if (getNumberType(Max.GetType()) != RangeValueTypes.Integer)
                {
                    throw new VueServerException("範囲指定のバリデーションで整数の項目に整数以外の「Max」が設定されています。");
                }

                // タグの属性[max]に最小値を設定
                context.Attributes["max"] = Max.ToString();

                // 最大値の異常メッセージが設定されている場合はタグの属性[max-error-message]に設定
                if (!string.IsNullOrEmpty(MaxErrorMessage))
                {
                    context.Attributes["max-error-message"] = MaxErrorMessage;
                }
            }

            // StepとStepのエラーメッセージを設定
            if (Step != null)
            {
                // Stepは整数以外はエラー
                if (getNumberType(Step.GetType()) != RangeValueTypes.Integer)
                {
                    throw new VueServerException("範囲指定のバリデーションで整数の項目に整数以外の「Step」が設定されています。");
                }

                // タグの属性[step]に最小値を設定
                context.Attributes["step"] = Step.ToString();

                // 最刻み幅の異常メッセージが設定されている場合はタグの属性[step-error-message]に設定
                if (!string.IsNullOrEmpty(StepErrorMessage))
                {
                    context.Attributes["step-error-message"] = StepErrorMessage;
                }
            }
        }