Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Multiple Submit Buttons

$
0
0

Not sure where I am going wrong.  I have a wizard type form.  On the form I have a next and back button.  So far I have the next button working which is fine as this is intentional at this stage.  On this particular form in the sequence I want to add a third button for Add Another Procedure.

View Code:

@{
    ViewData["Title"] = "Add Procedure";
}<h2>Add Procedure To Quote</h2><form asp-action=" " method="post"><div class="form-horizontal"><hr /><div asp-validation-summary="ModelOnly" class="text-danger"></div><div class="form-group"><label class="col-md-2 control-label">Quote</label><div class="col-md-10"><select asp-for="QuoteID" class="form-control" asp-items="ViewBag.QuoteID" id="quoteID"><option>---Select Quote ---</option></select></div></div>
......<div class="form-group"><div class="col-md-offset-2 col-md-10"><input type="submit" value="Add Another Procedure" formaction="AddAnotherProcedure"  id="buttonrefresh" /></div></div><div class="form-group"><div class="col-md-offset-2 col-md-10"><input type="submit" value="<Back" class="btn btn-default" />   <input type="submit" value="Next>" formaction="QuoteSalesProcedure"  /></div></div></div></form>

Then in the controller I have:

 // POST: QuoteProcedures/AddAnotherProcedure
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> AddAnotherProcedure([Bind("EstimateMinutes,FrequencyID,ProcedureID,Quantity,QuoteID")] QuoteProcedure quoteProcedure)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(quoteProcedure);
                    await _context.SaveChangesAsync();



                    return RedirectToAction("QuoteSalesAnotherProcedure",  new { id = quoteProcedure.QuoteID });
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +"Try again, and if the problem persists " +"see your system administrator.");
            }



            return RedirectToAction("QuoteSalesAnotherProcedure", new { id = quoteProcedure.QuoteID });
        }

        // GET: QuoteProcedures/Create
        public IActionResult QuoteSalesAnotherProcedure(int id)
        {
            ViewData["FrequencyID"] = new SelectList(_context.Frequency.OrderBy(i => i.iFrequency), "FrequencyID", "iFrequency");
            ViewData["ProcedureID"] = new SelectList(_context.Procedures.OrderBy(p => p.ProcedureName), "ProcedureID", "ProcedureName");
            ViewData["QuoteID"] = new SelectList(_context.Quote.Include(q => q.QuoteRequest).OrderBy(q => q.QuoteRequest.QDescription),"QuoteID", "QuoteRequest.QDescription", id);
            ViewData["IDD"] = id;

            return View();
        }

However this doesn't seem to work.  My intent is to save the current procedure and reload the form.

If I get the form to reload, with mucking about, it doesn't save the record to the table and the next button fails to respond.  If I get the record to save then it doesn't reload for the next procedure so I assume it is going to the original create method.

Clearly I am not following something?  What is the issue?  How have I misunderstood?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>