Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 11-Mar-13 9:53am
Edited 11-Mar-13 10:06am
v2
Comments
Zoltán Zörgő at 11-Mar-13 16:51pm
   
And can you output the message in the caller view? How exactly do you call the partial view?
Sirak Alemu at 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ő at 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.
Sirak Alemu at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^].
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100