locked
Text Box Not Clearing After HttpPost RRS feed

  • Question

  • User2029849071 posted

    Hi,

    On my view, I have one text box that I have the user enter contents that I need to generate a PDF.  When the user submits the view, I have an action verb HttpPost on the action in the controller.  Everything works perfect and the PDF is generated and downloaded to the browser so the user can open and view.  My issue is that the contents of the text box are still there after the submit and I would like them cleared out.  I assume it is because I am using a return File, but I am not sure what the best practice would be to get the text box cleared after submitting.  Any help would be appreciated.

    public IActionResult GenerateWorkOrderPickSheet()
    {
         return View();
    }
    
    [HttpPost]
    public IActionResult GenerateWorkOrderPickSheet(WorkOrderPickSheetViewModel workOrderPickSheetViewModel)
            {
    
                if (workOrderPickSheetViewModel != null && ModelState.IsValid)
                {
              
                    //split the Work Order numbers into a list
                    List<string> workOrderList = workOrderPickSheetViewModel.WorkOrders.ToString().Replace("\r\n", "\n").Split("\n").ToList();
    
                    var globalSettings = new GlobalSettings
                    {
                        ColorMode = ColorMode.Color,
                        Orientation = Orientation.Portrait,
                        PaperSize = PaperKind.A4,
                        Margins = new MarginSettings { Top = 10, Bottom = 15 },
                        DocumentTitle = "Work Order Pick Sheet",
                    };
    
                    var objectSettings = new ObjectSettings
                    {
                        PagesCount = true,
                        HtmlContent = GetWorkOrderPickSheetString(workOrderList),
                        WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\css", "WorkOrderPickSheet.css") },
                        HeaderSettings = { FontName = "Verdana", FontSize = 6, Right = "Page [page] of [toPage]", Line = true },
                        FooterSettings = { FontName = "Verdana", FontSize = 6, Line = true, Center = "Work Order Pick Sheet" }
                    };
    
                    var pdf = new HtmlToPdfDocument()
                    {
                        GlobalSettings = globalSettings,
                        Objects = { objectSettings }
                    };
    
                    var file = _converter.Convert(pdf);
    
                    ModelState.Clear();
    
                    return File(file, "application/pdf", "Work Order Pick Sheet.pdf");
    
                }
                else
                {
                   
                    return View();
                }
               
            }

    Thanks,

    Tim

    Friday, July 19, 2019 8:15 PM

Answers

  • User475983607 posted

    Write a JavaScript timer that clears the input after a second or two.  Write the timer to the submit button click event.

    <div>
        <form method="post">
            <input id="Text1" type="text" name="Text1" />
            <input id="Submit1" type="submit" value="submit" />
        </form>
    
    </div>
    
    
    @section scripts {
        <script>
            $('#Submit1').click(function () {
                setTimeout(function(){ $('#Text1').val(''); }, 2000);
            });
        </script>
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 19, 2019 8:41 PM

All replies

  • User475983607 posted

    Write a JavaScript timer that clears the input after a second or two.  Write the timer to the submit button click event.

    <div>
        <form method="post">
            <input id="Text1" type="text" name="Text1" />
            <input id="Submit1" type="submit" value="submit" />
        </form>
    
    </div>
    
    
    @section scripts {
        <script>
            $('#Submit1').click(function () {
                setTimeout(function(){ $('#Text1').val(''); }, 2000);
            });
        </script>
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 19, 2019 8:41 PM
  • User-1204637165 posted
    <script type="text/javascript">
    
    function clearTextbox(){
       $('#textID').setText('');
    }
    
    setTimeout('clearTextbox', 2000);
    
    </script>

    This code would help you clear the textbox after 2 s

    Friday, July 19, 2019 9:03 PM