whats the best way to show and hide parts of an mvc view based on some logic : Im typing on a phone so please have mercy. I just have something im thinking about and something which ive been implementing in a lot of my code which i dont think is the best way of doing things..
you know after you submit a form you may want to direct back to the same page and display a success message and want to hide the submitted form inputs for example. Other times you may direct to a page with an optional paramter, like a query string, and based on that parameter you may want to show and hide certain things on your view.

Im not sure the best way to do this because i like keeping all logic in my controller and not putting logic in my view. 

You can accomplish this in webforms simply by seperating your elements in different panels and setting the hidden property in your cs controll.

The way ive been doing this in mvc (which i dont like) is for example with a ViewBag success message and an if statement in my view which checks if the viewbag is null .. if its not null it displays the success message else it displays some form inputs.  Other times you dont use a viewbag... for example a checkout page for a shopping cart... in your view you might check if the cart model is empty, of it is empty display a "sorry, your cart is empty"  message else display the cart table.. I dont like handling this with if logic in my view... what is the best solution? Is there another solution?


I could right out some example code here but im on my phone and my eyes are tired...

Controll:

     [HttpPost]
     public ActionResult Edit(Elephants elephants)
     {
         // do something with elephants 

         ViewBag.weldone = "Weldone, you have made a wonderful impact by submitting this crucial knformation about elephants to the world";
         return View();

     }

View:

     @if(ViewBag.weldone != null)
     {
          <p>@ViewBag.weldone</p>
     }

     else
     {
          //something you want to hide from the page on succesfull elephant save

     }