I have a view called Associations that has a drop down list and a button. When the user selects an option and presses submit, I want them to go to Association/{associationKey}. Association needs to work on get and post.
Currently, with the code below, when the form is posted, it DOES go to Association and displays the correct record, BUT it does not append the associationKey to the url.
So I am getting:
instead of:
http://localhost/Association/202
If I manually navigate to http://localhost/Association/202 everything works perfectly, so get and post are both working fine....I just want the key in the url after a post!
Surely there must be something super simple I am doing wrong. Relevant code below.
Thanks!
ASSOCIATIONS view:
<% Html.BeginForm("Association", "Staff", FormMethod.Post); %>
<%:Html.DropDownList("associationKey", new SelectList(Model.Associations.ToList(), "AssociationKey", "LegalName"))%>
<input type="submit" value="Edit The Selected Record" />
<% Html.EndForm(); %>
STAFF controller:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult Association(int associationKey)
{
return View("Association", new AssociationViewModel(associationKey));
}
GLOBAL.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Default", "{action}", new { controller = "Staff", action = "Default" });
routes.MapRoute("Associations", "Associations", new { controller = "Staff", action = "Associations" });
routes.MapRoute("Association", "Association/{associationKey}", new { controller = "Staff", action = "Association" });
}
ASSOCIATION view model:
public class AssociationViewModel
{
public Repository db = new Repository();
public Association Association {get; private set; }
public List TelephoneTypes { get; private set; }
public AssociationViewModel(int associationKey)
{
Association = db.AssociationById(associationKey);
TelephoneTypes = db.ListTelephoneTypes().ToList();
}
}