1

テキストボックスの値とリンク(追加)があるフォームがあります。ユーザーがテキストボックスにデータを入力して追加をクリックすると、入力したテキストが同じビューの textArea に追加されます。私はajax.actionlinkでこれをやろうとしましたが、入力されたテキストをパラメーターに渡す方法がわかりません。誰かが私が試すことができる別のアイデアを持っていますか.. HTMLフォームが既にあるため、Ajax.beginFormを使用できません。

前もって感謝します。

これは、これまでにajaxアクションリンクを使用したhtmlコードです。

                    <div class="editor-label">
                        <%: Html.Label("DefectID / FeatureID")%> <%: Html.TextBox("DefectID", "", new { @class = "required" })%> <%: Ajax.ActionLink("Add", "InsertDefectIDs", new AjaxOptions { UpdateTargetId = "DefectIds" }) %><%--<input type="button" name="add" value="Add" />--%>
                    </div>

                    <div class="editor-field">
                        <%: Html.TextAreaFor(model => model.DefectIds, new { rows = 5, cols = 12, @readonly = "true" })%>
                        <%: Html.ValidationMessageFor(model => model.DefectIds)%>
                    </div>
4

1 に答える 1

0

次のようなことができるはずです。

HTML

<div class="editor-label">
    <%: Html.Label("DefectID / FeatureID")%> 
    <%: Html.TextBox("DefectID", "", new { @class = "required" })%> 
    <input type="button" name="add" value="Add" onclick="AddDefectId();" />
</div>

<div class="editor-field">
    <%: Html.TextAreaFor(model => model.DefectIds, new { rows = 5, cols = 12, @readonly = "true" })%>
    <%: Html.ValidationMessageFor(model => model.DefectIds)%>
</div>

Javascript

<script type="text/javascript">
    function AddDefectId() {
        var defectId = document.getElementById('DefectId').value;

        if(defectId != "")
             document.getElementById('DefectIds').value += defectId + ","

        document.getElementById('DefectId').value = "";        
    }​
</script>

これはストレートな html/javascript の例です: http://jsfiddle.net/zJpRA/6/

于 2012-04-05T21:31:36.503 に答える