Search code examples
c#asp.net-mvcasp.net-mvc-3.net-4.0asp.net-mvc-3-areas

display success message after deletion


I need to display a success message to user after the file has been deleted. dont know how to do it. please help.

    public ActionResult deleteGeneratedInvoice(string invoiceNumber)
    {
        try
        {
            string fileName = invoiceNumber.Trim() + ".pdf";
            string filePath = HostingEnvironment.MapPath("~/Content/reports/");
            string fullFilePath = filePath + fileName;
            System.IO.File.Delete(fullFilePath);

            //What shall i return here to display message?
            return
        }
        catch (Exception e)
        {
            InvoiceSearchTool.Models.udtExceptionTable exception = new udtExceptionTable();
            exception.MethodName = "deleteGeneratedInvoice";
            exception.Exception = e.ToString();
            exception.Date = DateTime.Now;
            DYNAMICS_EXTEntities db = new DYNAMICS_EXTEntities();
            db.AddToudtExceptionTables(exception);
            db.SaveChanges(); 
            //return View ("Error");
        }
    }

Solution

  • //What shall i return here to display message?

    ViewBag.SuccessMessage = "File was successfully deleted";
    return View();
    

    In your deleteGeneratedInvoice view, write this somewhere that makes sense:

    <p>@(ViewBag.SuccessMessage ?? "")</p>