I'm very new to MVC, and just building my first site, using NerdDinner as an example. I'm wondering what is the best approach to displaying the result of a server-side process. eg on a screen where a user is asked to change their password - if the change fails validation then error messages are displayed as per NerdDinner pattern using the current view. If the change succeeds, ideally I want to stay on the same page, hide the change password controls and just display a "password change succeeded" message.
我是MVC的新手,只是使用NerdDinner构建我的第一个站点。我想知道显示服务器端进程结果的最佳方法是什么。例如,在要求用户更改其密码的屏幕上 - 如果更改未通过验证,则使用当前视图按照NerdDinner模式显示错误消息。如果更改成功,理想情况下我希望保持在同一页面上,隐藏更改密码控件并只显示“密码更改成功”消息。
The options seem to be to either, redirect to a new view with the success message, or have hidden controls on the view and show/hide them using values returned in the ViewData. Is there another more elegant way of doing this?
选项似乎是,使用成功消息重定向到新视图,或者在视图上使用隐藏控件,并使用ViewData中返回的值显示/隐藏它们。还有另一种更优雅的方式吗?
1 个解决方案
#1
1
I just do it like this:
我就是这样做的:
<% if (ViewData["success"] != null)
{ %>
<div class="success">Huge Success!</div>
<% }
else
{ %>
Such things belong to the View, so you really shouldn't be thinking too hard about how to get it pretty. It's pretty by design, because it's in your view.
这些东西属于View,所以你真的不应该过分思考如何让它漂亮。这很漂亮,因为它在你的视野中。
#1
1
I just do it like this:
我就是这样做的:
<% if (ViewData["success"] != null)
{ %>
<div class="success">Huge Success!</div>
<% }
else
{ %>
Such things belong to the View, so you really shouldn't be thinking too hard about how to get it pretty. It's pretty by design, because it's in your view.
这些东西属于View,所以你真的不应该过分思考如何让它漂亮。这很漂亮,因为它在你的视野中。