1

我有表单,其中有文本框值和链接(添加)。当用户在文本框中输入数据并单击添加时,它应该将输入的文本添加到同一视图的 textArea 中。我曾尝试使用 ajax.actionlink 执行此操作,但我似乎无法弄清楚如何将输入的文本传递给参数。谁能有另一个想法我可以尝试..我不能使用 Ajax.beginForm 因为我已经有 html 表单。

先感谢您。

这是到目前为止我使用 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 回答