В проекте Asp.net MVC Нажатие кнопки добавляет частичное представление в главное представление, не удалось обновить динамически загруженные элементы управления частичным представлением с помощью jQuery
Главный вид
<script>
function AddCustomer() {
$.get("DataEntryScreen").done(function (r) {
$('#DivDatEntry').html(r);
});
}
$('#btnCancel').click(function (e) {//not work on main view
alert();
$('#DivDatEntry').html("");
});
</script>
Частичное представление = DataEntryScreen.cshtml
@{
AjaxOptions o = new AjaxOptions();
o.OnSuccess = "OnSaveSuccess";
}
@using (Ajax.BeginForm("SaveCustomer", "SPA", o))
{
<table>
<tr>
<td>Customer Name:</td>
<td><input type="text" id="CustomerName" name="CustomerName" value="" /></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" id="Address" name="Address" value="" /></td>
</tr>
<tr>
<td>Age:</td>
<td><input type="text" id="Age" name="Age" value="" /></td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="submit" name="name" value="Save" />
<input type="button" name="name" value="Reset" />
<input id="btnCancel" type="button" name="name" value="Cancel" />
</td>
</tr>
</table>
}
Теперь динамически загружаемое частичное представление = "DataEntryScreen.cshtml" Идентификаторы управления
CustomerName, Address, Age для значений управления обновлением используйте следующий синтаксис jQuery
$('body').find('#CustomerName').attr('value', 'CustomerName');
or
$('#CustomerName').val('CustomerName');
Выше синтаксиса не удалось обновить значения элементов управления. Follow Эта отправляет информацию, но не может решить мою проблему.
Как обновлять динамически добавленные элементы частичного просмотра в jQuery