0

In one View I have 3 submit button like this

<input type="submit" id="btnUpload" name="button" value="Upload" />
<input type="submit" id="btnDownload" name="button" value="Download" /> 
<input type="submit" id="btnSave" name="button" value="Save" />

these buttons are inside the begin form

in controller

 [HttpPost]
 [ValidateAntiForgeryToken]
 public ActionResult BulkRenewalProcess(BusinessViewModel model, List<HttpPostedFileBase> BulkFile, string button)
 {
        if (button == "Upload")
        {
           model.PublicId = lstId;
           return View(model);
        }
        else if(button == "Download")
        {
           // After my business logic I am returning same view.
           return View(model);
        }
        else
        {

        }
 }

When I am clicking on Save button which is the 2nd click and posting the same model. I am not getting the model.PublicId on which I am assigning the value on upload button click.

Someone please help me how to get the value

tereško
  • 58,060
  • 25
  • 98
  • 150
Rocky
  • 4,454
  • 14
  • 64
  • 119

2 Answers2

0

If there are multiple rows and you are ajax posting changes to them without a full page load, then multiple forms each with the hidden value for the item they are saving can do it.

Another option is to have a hidden field at the page-form level where on click of a submit javascript intercepts and sets the hidden field value. Here's a sample of intercepting submit clicks to do some more work: How to use jQuery to onsubmit and check if the value is 2 - 5 characters?

Another option with a form encapsulating all items would be to have each submit link (assuming your submit buttons are per row rather than at the list level) generated with the id baked in something like <input type="Submit" value="1" title="Id is 1">

Community
  • 1
  • 1
Maslow
  • 18,464
  • 20
  • 106
  • 193
0

I have taken the session and stored the list in session which solved my problem

Rocky
  • 4,454
  • 14
  • 64
  • 119