I have a page that dynamically generates any number of divs. Inside the div is a bunch of user information with a text area and a button to close out the record. Please take a look at the HTML here (I’ve stripped out all the stuff not required to answer my quest):
<form action="/Recruiter" method="post">
<span id="1" class="underline" >Click Here</span>
<div id="notes_1" style="display: none;">
<textarea cols="30" id="PostBodyText" name="PostBodyText" rows="10"></textarea>
</div>
<input id="btnCloseOut" type="submit" name="Command" value="Close out" title="Close out."/>
<input type="hidden" name="recruiterQueueId" value="2" />
<input type= "hidden" name="queueRecordId" value="1" />
<span id="2" class="underline" >Click Here</span>
<div id="notes_2" style="display: none;">
<textarea cols="30" id="PostBodyText" name="PostBodyText" rows="10"></textarea>
</div>
<input id="btnCloseOut" type="submit" name="Command" value="Close out" title="Close out."/>
<input type="hidden" name="recruiterQueueId" value="2" />
<input type="hidden" name="queueRecordId" value="2" />
<span id="3" class="underline" >Click Here</span>
<div id="notes_3" style="display: none;">
<textarea cols="30" id="PostBodyText" name="PostBodyText" rows="10"></textarea>
</div>
<input id="btnCloseOut" type="submit" name="Command" value="Close out" title="Close out."/>
<input type="hidden" name="recruiterQueueId" value="2" />
<input type="hidden" name="queueRecordId" value="3" />
And finally here’s the what the controller piece that gets posted to looks like:
[HttpPost]
public ActionResult Index(int recruiterQueueId, int queueRecordId, string postBodyText)
{
CloseOutQueueRecordResponse response =
checkInService.CloseOutQueueRecordRequest
(
new CloseOutQueueRecordRequest()
{
RecruiterQueueId = recruiterQueueId,
QueueRecordId = queueRecordId,
CloseOutNotes = postBodyText
}
);
// details ommitted...
}
The problem is the information from the first div is always posted no matter which button I hit. I’m not complaining about that, that’s what it should do.
I’m just looking for ideas/suggestions on how to post the information I want
OR
… the other thing I wsa thinking was inside of a button using an @Html.ActionLink …. this almost worked for me. I was able to get the appropriate IDs to the controller, but I’m not yet able to extract the contents of the text area in this case…
Any tips/suggestions?
If you are only interested in the data from one “div”, you could create a form for every div. Only the data from the form the submit button is in, will be posted.
Also: The ID’s of every element should be unique. So you should work on that to. You do not have to supply an ID.
The names do not have to be unique. If you are using multiple forms you will be fine.