0

This is my Controller:

namespace OBBMS.Controllers
{
    public class BDMController : Controller
    {
        public ActionResult Index()
        {   
            OBBMS.Models.User objUser = new Models.User();
            objUser.lstUser = DB_Interactions.BDMGetUsers("Pending");
            return View(objUser);
        }

        [HttpPost]
        public ActionResult Index(OBBMS.Models.User objUser)
        {
            return View();
        }
    }
}

Here is View Code:

@model OBBMS.Models.User
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_LayoutBloodDonationManagement.cshtml";
}
@using (Html.BeginForm("Index", "BDM", FormMethod.Post, new {id = "BDM"}))
{
<table id="mytable" class="table table-bordred table-striped">
<thead>
    <tr>
        @*<th>Post ID</th>*@
        <th>Full Name</th>
        <th>Blood Group</th>
        <th>Email Address</th>
        <th>Contact No</th>
        <th>Address</th>
        <th>Post Title</th>
    </tr>
</thead>
<tbody>
    @foreach(var obj in Model.lstUser)
    {
        <tr>
            <td style="display:none!important;">@obj.PostID</td>
            <td>@obj.FullName</td>
            <td>@obj.BloodGroupName</td>
            <td>@obj.EmailAddress</td>
            <td>@obj.ContactNo</td>
            <td>@obj.Address</td>
            <td>@obj.PostTitle</td>
            <td><input type="submit" value="Approve" class="btn btn-primary btn-xs" data-title="Approved" data-toggle="modal" data-target="#edit" /></td>
        </tr>
    }
</tbody></table>}

I have a submit button at the end of each row, I need to get Single instance of User object instead of complete list in HttpPost ActionResult Method when a specific row button is click. I just need to get the object only the row button is clicked.

If possible: I do not want to use any JavaScript/jQuery/Ajax, everything should be done in APS.NET MVC framework.

If not possible: Suggest me best and easiest way to do it.

4
  • You do not have a <form> and you do not have any form controls so there is nothing to submit. Are you wanting to update the status (to approved) of an record in your collection? Commented Sep 29, 2018 at 8:14
  • I think you can add a <form> tag inside <td> tag targeting your Edit action in your submit button setting your user-id as key parameter to send. Then manage it in your Edit action. Commented Sep 29, 2018 at 8:40
  • you can make separate form per td and using hidden field you can make it work. Commented Sep 30, 2018 at 2:46
  • now I added form tag Commented Oct 12, 2018 at 19:44

1 Answer 1

1

One possible solution is to use the HTML 5 form attribute. The attribute can be used to indicate which form an element belongs to. For example:

  @foreach(var obj in Model.lstUser)
  {
      <tr>
         <td><form id="@("form"+obj.PostID)"><input type="hidden" name="id" value="@obj.PostID" /></form></td>
         <td><input form="@("form"+obj.PostID)" type="text" name="FullName" value="@obj.FullName" /></td>
         <td><input form="@("form"+obj.PostID)" type="text" name="BloodGroupName" value="@obj.BloodGroupName" /></td>
        <-- more td elements here -->
        <td><input form="@("form"+obj.PostID)" type="submit" value="Approve" class="btn btn-primary btn-xs" data-title="Approved" data-toggle="modal" data-target="#edit" /></td>
      </tr>
  }

Check here for a list of supported browsers.

Sign up to request clarification or add additional context in comments.

1 Comment

it works in many situations for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.