I have a blog app where the user can insert comments to be approved/denied from the admin.
Here is the code for the View on which the administrator can give/deny approvation through Ajax:
<div id=news_comment_state_@(Model.Id)>@(Model.FlApproved?"Approved":"Denied")</div>
@Ajax.ActionLink("Approve", "ApproveDenyComment", new { IdComment = Model.Id, ApproveDeny=true }, new AjaxOptions { UpdateTargetId = "news_comment_state_"+@Model.Id})
<br />
@Ajax.ActionLink("Deny", "ApproveDenyComment", new { IdComment = Model.Id, ApproveDeny=false }, new AjaxOptions { UpdateTargetId = "news_comment_state_"+@Model.Id})
In the Controller, the ApproveDenyComment returns the "Approve"/"Denied" strings for the 2 actions.
It runs but I don’t like it too much, I think there is a better and cleaner way to do it but I don’t know it, can anyone help me?
Cris,
I would be tempted to return a partialview via $ajax in respect to that user and repopulate the comments div. keeps everything consistent and saves error prone server/clientside logic disconnect (i.e. if the error status flag were to change in the future for whatever reason, then you’re in trouble).
really has no peformance issues and many benefits in terms of consistency.