Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing data from View to Controller
    primarykey
    data
    text
    <p>In an ASP.NET MVC application, I'm making logic for Admin to accept or reject new members. I'm showing a list of members and two buttons Accept and Reject, like this:</p> <pre><code>&lt;% foreach (var mm in (ViewData["pendingmembers"] as List&lt;MyMember&gt;)) %&gt; &lt;% { %&gt; &lt;tr&gt;&lt;td&gt;Username:&lt;%=mm.UserName %&gt;&lt;/td&gt;&lt;td&gt; &lt;tr&gt;&lt;td&gt;Firstname:&lt;%=mm.FirstName %&gt;&lt;/td&gt;&lt;td&gt; ...etc... &lt;tr&gt; &lt;td&gt; &lt;% using (Html.BeginForm("AcceptPendingUser", "Admin")) { %&gt; &lt;input type="submit" value="Accept" /&gt; &lt;% } %&gt; &lt;/td&gt; &lt;td&gt; &lt;% using (Html.BeginForm("RejectPendingUser", "Admin")) { %&gt; &lt;input type="submit" value="Reject" /&gt; &lt;% } %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% } %&gt; </code></pre> <p>So, the list of pending member data is in a list of MyMember-objects. Each MyMember object will be printed out member and two buttons are setup for the admin to either accept or reject a pending member. </p> <p>Then, in the controller I'm separating the handling of those two input fields/forms, like this:</p> <pre><code>public ActionResult AcceptPendingUser() { // TODO: Add code to save user into DB and send welcome email. return RedirectToAction("Index"); } public ActionResult RejectPendingUser() { // TODO: Add code to remove user from PendingUsers list and send rejection email. return RedirectToAction("Index"); } </code></pre> <p>I would like to directly get the object next to the button the user pressed. How can I send the MyMember object from the View to the controller? Or how do I send perhaps a numeric index with button press? Maybe with a hidden field?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload