It is actually pretty easy with jQuery. Let's say your link is something like this:
<a href="javascript:flagInappropriate(<%=Model.PostId%>);">Flag as inappropriate</a>
Create a javascript to call the action in your controller to check and flag as necessary:
function flagInappropriate(postId) {
var url = "<CONTROLLER>/<ACTION>/" + postId;
$.post(url, function(data) {
if (data) {
// callback to show image/flag
} else {
// callback to show error/permission
}
});
}
In you action method in your controller will probably look like this:
[AcceptVerbs("POST")]
public bool FlagAsInappropriate(int id) {
// check permission
bool allow = CheckPermission();
// if allow then flag post
if (allow) {
// flag post
return true;
} else {
return false;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…