我有表格,我有文本框值和链接(添加)。当用户将数据输入到文本框并单击添加时,应将输入的文本添加到同一视图上的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>
答案 0 :(得分: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/