4
Guys, in my application that manages Courses, i have a sign-up screen, where the student clicks on the button "enrollment" and enrolls in the course, and the amount of vacancies field is decreasing. The problem is that my View
does not update after the student clicks the button "enrollment". I have to press the update button browser so that the View
be updated. How do I make this View
is automatically updated after clicking the button "enrollment"?.
My View
@model IEnumerable<MeuProjeto.Models.Curso>
<h2>Catálago de Cursos</h2>
@Html.ValidationSummary(true)
@TempData["MensagemErro"]
<table class="table table-hover">
<tr>
<th>
Curso
</th>
<th>
Sigla
</th>
<th>
Ementa
</th>
<th>
Inicio
</th>
<th>
Fim
</th>
<th>
Turno
</th>
<th>
Status
</th>
<th>
Quantidade de Vagas
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Nome_Curso)
</td>
<td>
@Html.DisplayFor(modelItem => item.Sigla)
</td>
<td>
<a href="@Url.Action("Ementa", "Curso")" data_toggle="modal" data_target="#modalaviso">Ementa</a>
</td>
<td>
@Html.DisplayFor(modelItem => item.Dt_Inicio)
</td>
<td>
@Html.DisplayFor(modelItem => item.Dt_Fim)
</td>
<td>
@Html.DisplayFor(modelItem => item.Turno)
</td>
<td>
<input type="text" name="Status" id="Status" value="@Html.DisplayFor(modelItem => item.Status)" readonly class="Status" />
</td>
<td>
@Html.DisplayFor(modelItem => item.Qtd_Vagas)
</td>
<td>
<div class="btn-group">
<div class="col-md-offset-2 col-md-10">
@if (item.Qtd_Vagas > 0)
{
<input type="submit" value="Inscrição" name="detalhes" class="inscricao btn btn-success" data_toggle="modal" data_target="#modalAviso" data-inscricaoid="@item.Id"/>
}
else
{
<input type="submit" value="Não há vagas" name="detalhes" class="inscricao btn btn-default" disabled="disabled"/>
}
</div>
</div>
</td>
</tr>
}
</table>
<div class="form-group">
<a href="@Url.Action("Index", "Home")"><input type="button" value="Voltar" class="btn btn-danger" /></a>
</div>
<br />
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$(document).ready(function() {
$(".inscricao").click(function() {
$.ajax({
type: "POST",
url: "Inscricao/",
data: {inscricaoId: $(this).data("inscricaoid")},
success: function() {
$(this).attr("disabled", "disabled");
}
});
});
});
</script>
}
Have you debugged your jquery function? It seems that Document.ready is not acting for the second time. Debug what happens when you click the button and post here to better help. I say this because I’ve had similar problems with Document.ready and I was able to solve it.I’m not claiming to be this, so posting the debug result is very important to the site’s staff.
– pnet