tags:

views:

34

answers:

3

Reading from this blog by Stephen Walther, I'd like to have my Create view post to my Insert action.

Stephen suggests that after my Insert action is done, to redirect to the user to another action. I guess I could redirect them to the Detail view of the object they just created, but I'm curious to know if there are other strategies to let the use know that they successfully submitted a valid object and that the object was saved to my database.

Specifically, I'd like to let the user know what they just did, and also prevent refreshes of the page from attempting to re-post the data. Ideally, I could do this without an intermediary page. Is there a cross-request ViewData that I can stuff this message into? Something similar?

+1  A: 

You can use TempData, for this, TempData will be available after you redirect the user to another action (like to index action again)

TempData["userMsg"] = "Product Created";
RedirectTo("List", "Products");
Rafael Mueller
+1  A: 

Like @Rafael says, you could put your message in the TempData collection. Then on the page you're going to, include JBar and have it show a message.

<% 
var message = TempData["UserMessage"];
if(message != null)
{%>
    <script>
        $(function(){
            $.bar({message: "<%: message %>"});
        });
    </script>
%<}%>

I have a customized version of JBar that would work really well for this scenario (it doesn't require a button click). Also, to keep this solution general I would actually put the above code on your master page.

Ryan
+1  A: 

I asked a similar question a month or so ago and got some good responses:

What is the recommended approach to providing user notification confirmations

In short, you may want to consider using HtmlExtensions which can be useful in handling user updates and notifications.

Hope this helps

Remnant