I am new to web development and am having a problem with my ajax call to load a page dynamically.
This is my JS :
$(function () {
$('.trEnfant').on('click', function (e) {
var id = $(this).attr("id");
$.ajax(
{
type:"Get",
url: '@Url.Action("DossierEnfant", "Enfant")',
data: {enfantId : id},
success: function (result)
{
$('#divDossierEnfant').html(result);
},
error: function (e)
{
alert('ca marche po...');
}
});
});
});
Now this is my controler :
public ActionResult DossierEnfant(string enfantId)
{
DossierEnfantViewModel model = new DossierEnfantViewModel();
model.Enfant = personneAppService.RecupererEnfant(new Guid(enfantId));
return View(model);
}
Finally my cshtml :
<div>
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Enfants</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-2">
<button class="btn btn-primary btn-block"><i class="fa fa-plus-circle"></i> @L("Ajouter")</button>
</div>
<div class="col-lg-10">
<table class="table table-bordered table-condensed table-hover">
@foreach (var item in Model.Enfants)
{
<tr id=@item.Id class="trEnfant">
<td class="col-md-6">@item.Nom</td>
<td class="col-md-5">@item.Prenom</td>
<td class="col-md-1 text-center">
<a class="btn btn-warning btn-xs" role="button" href="#"><i class="fa fa-minus-circle"></i></a>
</td>
</tr>
}
</table>
</div>
</div>
</div>
</div>
</div>
<div id="divDossierEnfant" class="row">
</div>
I tried going live with html.action and it works fine, but my ajax call always generate error...
this is my views folder : viewfolder
An idea ?