c# - MVC5 POST form retrieves data from previous index -


i populated view model passed in controller. each loop generate hyperlink button should pass in guid. however, when clicked on button , initiated post request, guid belongs button of previous index.

however, after checking element using chrome's inspection tool, button has correct guid attached it. when button clicked (posting), guid passed parameter belongs previous index's.

for example:

button (guid 1000)

button b (guid 2000)

button c (guid 3000)

when click on button b, guid passed posting 1000, belongs button a.

index.cshtml

@foreach (var item in model) {            <tr>               <td>                  @html.displayfor(modelitem => item.patientname)               </td>               <td>                  @html.displayfor(modelitem => item.nric)               </td>               <td>               @using (html.beginform("patient", "maincontroller", new { guid = item.patientid }, formmethod.post, new { id = "submitrequest" })) {                @html.antiforgerytoken()                 <a href="javascript:document.getelementbyid('submitrequest').submit()" onclick="return confirm('a pop message.');" class="btn btn-success glyphicon glyphicon-plus" title="request"></a>                     }                </td>              </tr>           } 

maincontroller.cs

// post: doctor/patient         [httppost]         [validateantiforgerytoken]         public actionresult patient(string guid) {             try {                 if (modelstate.isvalid) {                     var currenttime = datetime.now;                     db.appeal.add(new appeal {                         doctorid = user.identity.getuserid(),                         patientid = guid, // issue here.                         time = currenttime,                          isapprove = false                     });                     tempdata["message"] = "appeal being processed. check request page outcome.";                     db.savechanges();                     return redirecttoaction("patient");                 }             } catch (dataexception dex) {             }             return redirecttoaction("patient");         } 

may know did go wrong? have been trying fix past 1 hours, can't seem figure out what's causing it.

this line

@using (html.beginform("patient", "doctor", new { guid = item.patientid }, formmethod.post, new { id = "submitrequest" }))  

the id same form elements , submitting forms through javascript using same id element. when call

document.getelementbyid('submitrequest`) 

it return first form element given id. need have different id attribute attached each form element.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo