I am using following code to update a modal in my view and then replacing the content using controller action.
$('#myTable1, #myTable2').on('click', 'a.editor_edit', function (e) {
e.preventDefault();
//console.log(e.target);
//console.log(this.closest('table'));
var passedId = $(this).attr("id");
//console.log(passedId);
$.get('/Controller/EditCustomer/' + passedId, function (data) {
console.log(data);
$('#partial').replaceWith(data);
$('#reportModal').modal('show');
});
});
But when the modal appears , it still holds the data for the 1st id. And it never updates the content inside modal.
I suspect it is either the modal or I am displaying the modal too soon (before replace complete).
When I do a console.log , I get new data each time though...
In Index.cshtml , I have this .
<div id="partial" style="display: none">
</div>
And the partial view looks like ,
@model MyModel
<div class="modal fade" id="reportModal" tabindex="-1" role="dialog" aria-labelledby="reportModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="reportModalLabel">Edit Customer:</h4>
@if (Model != null)
{
using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Customer</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ID)
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
}
</div>
<div class="modal-body">
<canvas id="reportsChart" width="400" height="400"></canvas>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="modal-cancel-b">Cancel</button>
<button type="button" class="btn btn-primary" aria-haspopup="true" aria-expanded="false">Save</button>
</div>
</div>
</div>
</div>