This question is really similar to my last one but this has to do with passing multiple parameters. My controller has two methods with the same name but one gets passed a nullable int to determine which action to take on post (I don't know if that's a good design decision). Here's the code:

public ActionResult EventDetails(int? eventID)
{
    EventDetailsViewModel model = new EventDetailsViewModel();

     if (eventID != null)
     {
      model.afterPost = false;
      model.currentAttendance = getCountAttending(eventID);
      model.currentUser = getCurrentUserProfile(User.Identity.Name);
      model.eventDetails = getEventDetails(eventID);
      model.eventRestrictions = getEventRestrictions(eventID);
      model.usersAttending = getUsersAttending(eventID);
      return View(model);
     }
     else
     {
      return View();
     }
 }

 [HttpPost]
 public ActionResult EventDetails(int? eventID, int? action)
 {
     EventDetailsViewModel model = new EventDetailsViewModel();

     if (eventID != null)
     {
      model.afterPost = true;
      model.currentAttendance = getCountAttending(eventID);
      model.currentUser = getCurrentUserProfile(User.Identity.Name);
      model.eventDetails = getEventDetails(eventID);
      model.eventDetails["ActionID"] = action.ToString();
      model.eventRestrictions = getEventRestrictions(eventID);
      model.usersAttending = getUsersAttending(eventID);
      return View(model);
     }
     else
     {
      return View();
     }
 }

the view is huge but I'll post the relevant piece:

@if(User.Identity.IsAuthenticated)
{
 if (!Model.eventDetails["Event_Owned"].Equals("true"))
 {
     <div class="joinEventButton">
      @if(Model.eventDetails["Event_Current"].Equals("true"))
      {
          <form method="post" action="@Url.Action("EventDetails", "Event", new{eventID = Int32.Parse(Model.eventDetails["EventID"]), action = Int32.Parse(Model.eventDetails["CODE_RequestInvitation"])})">
           <input type="submit" value="Request Invitation" class="submitButton submitButton-green"/>
          </form>
      }
      else
      {
          <button class="disabledButton disabledButton-grey">Request Invitation</button>
      }
     </div>
 }

and just for good measure, my routes:

    public static void RegisterRoutes(RouteCollection routes)
    {
        //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

So the idea is that based on authentication and whether they own a specific event they are looking at, they will have different buttons show on the screen. This certain one is for when they want to join an event they can push a button to request an invitation. The controller knows this because of the int value being passed back as CODE_RequestInvitation. The action being returned is always null. I can't figure out what's wrong.

Related posts

Recent Viewed