如何使用jquery更新我的视图?

时间:2015-03-16 18:37:42

标签: jquery asp.net-mvc-4

我正在使用带有剃刀视图的MVC 4。我想要做的是在视图中添加我的div类的新实例。我的jquery需要什么?

这是div。

<input type="button" id="btAdd" value="Add Answer"/>
 <div class="AnswerLabel">
        @Html.LabelFor(model => model.answer.AnswerText, new {id = "AnswerLabelField"})
    </div>
    <div class="AnswerEditor">
        @Html.EditorFor(model => model.answer.AnswerText, new {id = "AnswerEditorField"})
        @Html.ValidationMessageFor(model => model.answer.AnswerText)
    </div>

Jquery的

$(document).ready(function () {
$('#btAdd').click(function () {
    //what do i need here;
    return false;
});

});

2 个答案:

答案 0 :(得分:0)

使用.append(.html())

$('body').append($('.AnswerEditor').html());

答案 1 :(得分:0)

<input type="button" id="btAdd" value="Add Answer"/>
<div id="attach">
 <div class="AnswerLabel">
        @Html.LabelFor(model => model.answer.AnswerText, new {id = "AnswerLabelField"})
    </div>
    <div class="AnswerEditor">
        @Html.EditorFor(model => model.answer.AnswerText, new {id = "AnswerEditorField"})
        @Html.ValidationMessageFor(model => model.answer.AnswerText)
    </div>
</div>


$(document).ready(function () {
$('#btAdd').click(function () {
    $('#attach').append('html content here');
    return false;
});

});