Click here to Skip to main content
15,891,841 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello:
I am using Razor view engine for the view and there are a few partial views on this page. I am setting error/status messages on the controller and trying to access these messages on the partial view using the ViewBag. For some reason, I am not seeing this message coming to the view.

I am adding the relevant line of codes here and any help would be appreciated...

Controller: InviteeController.cs and Action: InsertInvitee
ViewBag.Message = "Your have already added this guest";

PartialView: _InsertInvitee
<div id="uiError" class="alert alert-success" style="display: none;">
<strong>@ViewBag.Message</strong>
</div>
        
Regards
Posted
Updated 11-Mar-13 9:06am
v2
Comments
Zoltán Zörgő 11-Mar-13 16:51pm    
And can you output the message in the caller view? How exactly do you call the partial view?
Jonny Galt 11-Mar-13 17:25pm    
The partialView is a modal dialog that is called with this line of code as an anchor...
Open anchor tag
id="uiBtnManual" rel="/Invitee/InsertSingleInvitee" title="Import your guests manually">Manual Insert
Close anchor tag

Here is the Ajax form

@using (Ajax.BeginForm(
"InsertSingleInvitee",
"Invitee",
new AjaxOptions
{
UpdateTargetId = "updateInsert",
InsertionMode = InsertionMode.Replace,
OnSuccess = "showUpdateInsertMessage",
OnFailure = "showUpdateInsertError"
},
new
{
@class = "form-horizontal"
}))
{....}
Zoltán Zörgő 11-Mar-13 17:30pm    
If there is a roundtrip to the server, ViewBag won't pass. It is available only if you call the partial view directly from within the view.
Jonny Galt 11-Mar-13 17:33pm    
So what would be the right way to pass a dynamic status message from the controller to the dialog partial view after inserting a record. Any pointer to a resource would be appreciated...

1 solution

As I see you don't really use a partial form. You might have been defined it as partial, but it is just a layout-less normal view. Since ajax form is doing a callback to an action, you should pass the message as result of the callback.
Read this one for a short but really intuitive description of Ajax.BeginForm's usage in comparison with Html.BeginForm: Html.BeginForm() vs Ajax.BeginForm() in MVC3[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900