Cant Even Figure Out What Terms to Use to Search By

BitLost

Active member
Joined
Dec 10, 2016
Messages
35
Programming Experience
Beginner
I have been playing with this idea a couple of days and frustrated by google not returning anything I can make sense of I am thinking I am phrasing the question wrong.

What I have is a view for capturing input from the user. In this case a specific procedure.

However there is no reason only one procedure may be required, in fact many often would be.

What I am wanting to do is add a button to the view to save the record and reload the view for the next entry. I assumed this would be a case of redirecting to the create method after saving, however this doesn't result in a reload, so perhaps I am missing something in my code or thinking. Not to be deterred I did a google search but the returns I am getting don't look like what I am asking. I assume I am phrasing my question to Google badly?

C#:
[COLOR=green]// GET: QuoteProcedures/AddNew[/COLOR]
       [COLOR=blue]public[/COLOR] [COLOR=#2b91af]IActionResult[/COLOR] AddNew([COLOR=blue]int[/COLOR] id)
       {
           ViewData[[COLOR=#a31515]"FrequencyID"[/COLOR]] = [COLOR=blue]new[/COLOR] [COLOR=#2b91af]SelectList[/COLOR](_context.Frequency.OrderBy(i => i.iFrequency), [COLOR=#a31515]"FrequencyID"[/COLOR], [COLOR=#a31515]"iFrequency"[/COLOR]);
           ViewData[[COLOR=#a31515]"ProcedureID"[/COLOR]] = [COLOR=blue]new[/COLOR] [COLOR=#2b91af]SelectList[/COLOR](_context.Procedures.OrderBy(p => p.ProcedureName), [COLOR=#a31515]"ProcedureID"[/COLOR], [COLOR=#a31515]"ProcedureName"[/COLOR]);
           ViewData[[COLOR=#a31515]"QuoteID"[/COLOR]] = [COLOR=blue]new[/COLOR] [COLOR=#2b91af]SelectList[/COLOR](_context.Quote.Include(q => q.QuoteRequest).OrderBy(q => q.QuoteRequest.QDescription),
                                           [COLOR=#a31515]"QuoteID"[/COLOR], [COLOR=#a31515]"QuoteRequest.QDescription"[/COLOR], id);
           ViewData[[COLOR=#a31515]"IDD"[/COLOR]] = id;
 
           [COLOR=blue]return[/COLOR] View();
       }
 
       [COLOR=green]// POST: QuoteProcedures/AddAnotherProcedure[/COLOR]
       [COLOR=green]// To protect from overposting attacks, please enable the specific properties you want to bind to, for [/COLOR]
       [COLOR=green]// more details see http://go.microsoft.com/fwlink/?LinkId=317598.[/COLOR]
       [[COLOR=#2b91af]HttpPost[/COLOR]]
       [[COLOR=#2b91af]ValidateAntiForgeryToken[/COLOR]]
       [COLOR=blue]public[/COLOR] [COLOR=blue]async[/COLOR] [COLOR=#2b91af]Task[/COLOR]<[COLOR=#2b91af]IActionResult[/COLOR]> AddAnotherProcedure([[COLOR=#2b91af]Bind[/COLOR]([COLOR=#a31515]"EstimateMinutes,FrequencyID,ProcedureID,Quantity,QuoteID"[/COLOR])] [COLOR=#2b91af]QuoteProcedure[/COLOR] quoteProcedure)
       {
           [COLOR=blue]try[/COLOR]
           {
               [COLOR=blue]if[/COLOR] (ModelState.IsValid)
               {
                   _context.Add(quoteProcedure);
                   [COLOR=blue]await[/COLOR] _context.SaveChangesAsync();                    
                   [COLOR=blue]return[/COLOR] RedirectToAction([COLOR=#a31515]"AddNew"[/COLOR],  [COLOR=blue]new[/COLOR] { id = quoteProcedure.QuoteID });
               }
           }
           [COLOR=blue]catch[/COLOR] ([COLOR=#2b91af]DbUpdateException[/COLOR] [COLOR=green]/* ex */[/COLOR])
           {
               [COLOR=green]//Log the error (uncomment ex variable name and write a log.[/COLOR]
               ModelState.AddModelError([COLOR=#a31515]""[/COLOR], [COLOR=#a31515]"Unable to save changes. "[/COLOR] +
                   [COLOR=#a31515]"Try again, and if the problem persists "[/COLOR] +
                   [COLOR=#a31515]"see your system administrator."[/COLOR]);
           }
 
          
 
           [COLOR=blue]return[/COLOR] RedirectToAction([COLOR=#a31515]"AddNew"[/COLOR], [COLOR=blue]new[/COLOR] { id = quoteProcedure.QuoteID });
       }
Is the code I am working with.

Can someone explain why this doesn't work?

What is the approach I should try?

What phrase or terms I should use to Google this question?
 
Figured some of it out.

1: I was redirecting to the wrong action
2: I had the view aspaction set to an action in my controller. Removing this and tying the buttons to the actions directed the form to reload as I intended.

One mystery remains however...Why isn't the view component reloading when the form is saved? Do I need to explicitly instruct it to refresh? Can I do this from controller?
 
Back
Top Bottom