mettre à jour un champ du model après actions jquery.
Salut.
J'ai un système de vote où un utilisateur peut voter pour un cours.
Voici la page principale:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<iitgovern.ViewModels.Vote.CourseVoteViewModel>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
IITGovern - Vote in
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>On going votes</h2>
<table>
<tr>
<th>Course</th>
<th>
Total Votes
</th>
<th></th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: item.Course.course_name %>
</td>
<td>
<%: item.TotalVotes %>
</td>
<td>
<% Html.RenderPartial("VoteStatus",item); %>
</td>
</tr>
<% } %>
</table>
</asp:Content> |
Et voici la page partiel votestatus:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<iitgovern.ViewModels.Vote.CourseVoteViewModel>" %>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
function showUnvote() {
$("#unvotemsg").css("display", "block");
$("#votemsg").css("display", "none");
}
function showVote() {
$("#votemsg").css("display", "block");
$("#unvotemsg").css("display", "none");
}
</script>
<div id="votebox">
<% if (Request.IsAuthenticated)
{ %>
<% if (Model.Course.HasUserVoted(Context.User.Identity.Name))
{ %>
<script type="text/javascript">$(showUnvote);</script>
<% }
else
{ %>
<script type="text/javascript">$(showVote);</script>
<% } %>
<div id = "unvotemsg" style="display: none;">
You have voted !
<%= Ajax.ActionLink("Undo vote",
"UndoVoteForCourse",
new { id = Model.Course.course_id },
new AjaxOptions { OnSuccess = "showVote"})%>
</div>
<div id = "votemsg" style="display: none;">
<%= Ajax.ActionLink("Vote for this course",
"VoteForCourse",
new { id = Model.Course.course_id },
new AjaxOptions { OnSuccess = "showUnvote"})%>
</div>
<% }
else
{ %>
<%: Html.ActionLink("Logon to vote for course","Logon","Account") %>
<% } %>
</div> |
Grosso modo, selon si l'utilisateur a voté, ou non j'affiche la div qui faut. Puis une fois qu'il vote, je cache la #votemsg et montre #unvotemsg...
Ca marche mais le souci est que je souhaite aussi que:
Code:
1 2 3 4
|
<td>
<%: item.TotalVotes %>
</td> |
de la page principale soit changé sans avoir à recharger toute la page...
Comment faire?