0

任意のタイプに接続できるように UIHint を作成する必要があり、機能しました。チェックボックスが選択されている場合、チェックボックスが選択されていない場合、データは非表示になり、null を渡す必要があります。

しかし@Html.EditorForModel()、うまくいきませんでした。

モデル内:

[UIHint("_YesNoNull")]
[DisplayName("Ссылка на место проведения")]
public string VenueUrl { get; set; }

_YesNoNull コントロール:

@{
    Guid guid = Guid.NewGuid();
    var propertyName = this.ViewData.ModelMetadata.PropertyName;
}
<script type="text/javascript">
    $(function () {
        $('#@(propertyName)_checkbox').click(function () {

            var checked = $(this).attr('checked');
            if (checked != undefined) {
                $(this).val(true);
            }
            else {
                $(this).val(false);
            }
        });
    });
</script>
@Html.CheckBox("checkbox", false)
@Html.EditorForModel()//not worked

ソースhtml:

<div class="editor-label">
            <label for="VenueUrl">Ссылка на место проведения</label>
        </div>
        <div class="editor-field">
            <script type="text/javascript">
    $(function () {
        $('#VenueUrl_checkbox').click(function () {

            var checked = $(this).attr('checked');
            if (checked != undefined) {
                //show VenueUrl
            }
            else {
                //hide VenueUrl
            }
        });
    });
</script>
<input id="VenueUrl_checkbox" name="VenueUrl.checkbox" type="checkbox" value="true" /><input name="VenueUrl.checkbox" type="hidden" value="false" />


            <span class="field-validation-valid" data-valmsg-for="VenueUrl" data-valmsg-replace="true"></span>
</div>

私が結果を得たいもの:

   <div class="editor-label">
                <label for="VenueUrl">Ссылка на место проведения</label>
            </div>
            <div class="editor-field">
                <script type="text/javascript">
        $(function () {
            $('#VenueUrl_checkbox').click(function () {

                var checked = $(this).attr('checked');
                if (checked != undefined) {
                    //show VenueUrl
                }
                else {
                    //hide VenueUrl
                }
            });
        });
    </script>
    <input id="VenueUrl_checkbox" name="VenueUrl.checkbox" type="checkbox" value="true" /><input name="VenueUrl.checkbox" type="hidden" value="false" />

<div class="editor-field">

<input class="text-box single-line" id="VenueUrl" name="VenueUrl" type="text" value=""/>

</div>
    <span class="field-validation-valid" data-valmsg-for="VenueUrl" data-valmsg-replace="true"></span>
</div>
4

1 に答える 1

0

それ以外の

@Html.EditorForModel()//not worked

使用する

@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue)
于 2012-06-25T10:45:53.120 に答える