0

MVC3を使用して

動的コントロールを作成する質問フォームがあります。これらのコントロールには、次の検証を組み込む必要があります。

01 - Unicode String. No line breaks or tabs. DATA_MAX_LENGTH applies.
02 - Unicode Memo. Line breaks permitted. No tabs. DATA_MAX_LENGTH applies.
03 - Non-negative integer, as string.
04 - Non-negative Money (precision 18,2), as string.
05 - Date, as string, in the U.S. 4-digit-year format (e.g. 12/31/2012).
06 - Boolean (aka "Bit", "Yes/No"), as string, with "1" for True, "0" for False.

これらの値は、テーブル(SQLサーバー)の各質問項目のコントロールタイプとともに保存されます。

これらの検証を現在のコードに組み込む方法がわかりませんか?

public static string DisplayControl(this HtmlHelper helper, int controlId, string choices, string answer, int? controlType, int maxlength, int dataType)
        {
            var output = new StringBuilder();

            output.Append(@"<div class='answer'>");
            switch ((ControlTypes)controlType)
            {
                case ControlTypes.Calendar:
                    output.Append(String.Format("<input class='datepicker' type='text' id='{0}' name='{0}' value='{1}' />", controlId, answer));
                    break;
                case ControlTypes.DropDownList:
                    output.Append(String.Format("<select id='{0}' class='droplist' name='{0}'>", controlId));
                    var ddls = LookupList(choices, "|");
                    foreach (var ddl in ddls)
                    {
                        string selected = ddl.Equals(answer) ? "selected" : "";
                        output.Append(String.Format("<option value='{0}' class='dd_option' {1}>{0}</option>", ddl, selected));
                    }
                    output.Append("</select>");
                    break;
                case ControlTypes.RadioButtonList:
                    var rbls = LookupList(choices, "|");
                    output.Append("<fieldset class='radio_btns'>");
                    foreach(var rbl in rbls)
                    {
                        string rchecked = rbl.Equals(answer) ? "checked" : "";
                        output.Append(String.Format("<label><input class='qa_radio' type='radio' id='{1}' name='{0}' value='{1}' {2} />{1}</label>&nbsp;", controlId, rbl, rchecked)); 
                    }
                    output.Append("</fieldset>");
                    break;
                case ControlTypes.TextBoxMultiLineInteger:
                    output.Append(String.Format("<textarea id='{0}' name='{0}' class='multi_text'>{1}</textarea>", controlId, answer));
                    break;
                case ControlTypes.TextBoxMultiLineMaxLength:
                    output.Append(String.Format("<textarea id='{0}' name='{0}' class='multi_text'>{1}</textarea>", controlId, answer));
                    break;
                case ControlTypes.TextBoxSingleLineInteger:
                    output.Append(String.Format("<input class='single_line' type='number' id='{0}' name='{0}' value='{1}' {2} />", controlId, answer, maxlength > 0 ? String.Format("maxlength='{0}'", maxlength) : ""));
                    break;
                case ControlTypes.TextBoxSingleLineMaxLength:
                    output.Append(String.Format("<input class='single_line' type='text' id='{0}' name='{0}' value='{1}' {2} />", controlId, answer, maxlength > 0 ? String.Format("maxlength='{0}'", maxlength) : ""));
                    break;
            }

            output.Append("</div>");
            return output.ToString();
        }
4

0 に答える 0