I was reading about an example on Microsoft web site on how to show or hide a “Register” link for an object depend on whether the current user is already registered or not.
They add the following code to the view to display the Register link only if the current user is not already registered:-
<div id=”rsvpmsg”>
<% if (Request.IsAuthenticated) { %>
<% if (Model.IsUserRegistered(Context.User.Identity.Name)) { %>
<p>You are registered for this event!</p>
<% } else { %>
<%: Ajax.ActionLink( “RSVP for this event”,
“Register”, “RSVP”,
new { id=Model.DinnerID },
new AjaxOptions { UpdateTargetId=”rsvpmsg” }) %>
then on the register action method they also perform the same check to check if the user is already registered or not as follow:-
[Authorize, HttpPost]
public ActionResult Register(int id) {
Dinner dinner = dinnerRepository.GetDinner(id);
if (!dinner.IsUserRegistered(User.Identity.Name)) {
RSVP rsvp = new
RSVP();
// .....
So my question is why they perform the same check on the Post action method again,,, is there a chance for a user to call the POST register action method other than clicking on the Register link that will not be displayed if the user is already register ? … so why not to consider the
if (!dinner.IsUserRegistered(User.Identity.Name))
check on the action method as unnecessary ?
BR
Yes, it’s decidedly possible, and very easy.