MuriloKunze
MuriloKunze

Reputation: 15583

Properties of a mvvm class

I have a simple view with some data to insert/update in database and I need to show some message after save it. My doubt is: should this message be a property of my mvvm class? or should I put it into ViewBag/ViewData?

Upvotes: 0

Views: 44

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

You don't need to store the message as a property on your view model. You could have a property on your view model which indicates whether the operation succeeded or not. Then inside the view test this property and display the message:

@if (Model.Saved)
{
    <div>The item was saved</div>
}

and inside the controller action that performs the save you will set the property to true.

Upvotes: 2

Related Questions