Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个简单的视图,其中包含一些要在数据库中插入/更新的数据,我需要在保存后显示一些消息。我的疑问是:这条消息应该是我的 mvvm 类的属性吗?还是我应该把它放到 ViewBag/ViewData 中?
您不需要将消息作为属性存储在视图模型上。您可以在视图模型上有一个属性,指示操作是否成功。然后在视图中测试这个属性并显示消息:
@if (Model.Saved) { <div>The item was saved</div> }
在执行保存的控制器操作中,您将属性设置为 true。