I’ve got a form where users can edit members of a group.
So they have the possibilty to add members or remove existing members. So the Url goes like
“…/Group/Edit/4” Where 4 is the id of the group.
the view looks like this
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm("AddUser", "Group")) %>
<%{%>
<label for="newUser">User</label>
<%=Html.TextBox("username")%>
<input type="submit" value="Add"/>
</div>
<%}%>
<% using (Html.BeginForm("RemoveUser", "Group")) %>
<%{%>
<div class="inputItem">
<label for="groupMember">Bestehende Mitglieder</label>
<%= Html.ListBox("groupMember", from g in Model.GetMembers() select new SelectListItem(){Text = g}) %>
<input type="submit" value="Remove" />
</div>
<%}%>
</asp:Content>
The problem is that after adding or removing one user i lose the id of the group. What is the best solution for solving this kind of problem?
Should I use hidden fields to save the group id?
Thanks in advance.
You could use a hidden field or you could just parse the value into your route. I’m not sure how you’re parsing the group id to the view but it would look something like:
Then your controller will look something like this using the PRG pattern
The advantage to this method is that it’s more RESTful