I'm trying to figure out how to post the same form multiple times with an ID parameter, depending on which button is clicked. The problem I'm having is that the form only posts when the first button is pressed, but no other buttons makes the form post.
@using (Html.BeginForm())
{
foreach (var p in ViewBag.Projects)
{
<form role="form" id="frm">
<input type="hidden" value="@p.projId" name="projid" />
<p>@p.name <input type="submit" value="Add user"
class="btn btn-default btn-xs" id="btn-add" /></p>
</form>
}
}
I want to post the ID of the project when the button listed next to that project is pressed. My postfunction looks like this:
[HttpPost]
public ActionResult projects(int projid)
{
//testing
TempData["title"] = projid.ToString();
ViewBag.Projects = repo.GetAllProjectsForUser(User.Identity.Name);
return View();
}
Thanks for any help! The solution is probably easier than I think, starting to confuse myself :)