C# – Display Success message on the same page when submit

asp.net-mvcasp.net-mvc-3c

I'm using Html.Beginform in view page and get the parameters using FormCollection to the controller i want to return the Success message on the same ViewPage as a result.i'm using following code,

public string InsertDetails(FormCollection collection)
{     
     string result = "Record Inserted Successfully!";
     return result; 
}

It shows the success message on the new page.How can i resolve this? what i have to return to get the Success message on the same page?

Best Answer

Personally, I'd pop the result string into the ViewBag.

public ActionResult InsertDetails(FormCollection collection)
{
         //DO LOGIC TO INSERT DETAILS
         ViewBag.result = "Record Inserted Successfully!";
         return View(); 
}

Then on the web page:

<p>@ViewBag.result</p>