Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have 'Index' View with Searching Logic. When user clicks on 'Search' button, grid is displayed on same view using Partial View. 'Create New' action links for creating new record. All functionality working properly. My concern is displaying Success Message. If records Insert/Update/Delete Successfully I am displaying message on Index view. But even User clicks on 'Search' button, this message not hidden from user. I want to hide that message whenever user clicks 'Search' or refresh the page.
Please suggest.

What I have tried:

In Action method,
ViewBag.result = "Record Inserted Successfully...";
return View("Index");


In Index View,
 @ViewBag.result 


Also tried using ViewData & TempData.
Posted
Updated 18-Sep-16 12:59pm
v4
Comments
j snooze 16-Sep-16 17:52pm    
You could add a success message property to your view model and use that although I'm not quite understanding what you are trying to do other than blank out a message on a button click which can easily be done with javascript as well.

1 solution

As a fast solution to your requirement (in case you are not planing to use JavaScript which could be a valid solution) you can clear you result message variable "ViewBag.result" in the start of your search method logic

public search()
{
    ViewBag.result = "";
    
    \\....search logic
    
    return View("Index");
}


And I think you need to clear the variable in your other methods also "Insert/Update/Delete" in order not to have the same previous action result message.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900