Click here to Skip to main content
13,050,429 members (81,758 online)
Rate this:
Please Sign up or sign in to vote.
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;">
Posted 11-Mar-13 8:53am
Updated 11-Mar-13 9:06am
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?
Sirak Alemu 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(
new AjaxOptions
UpdateTargetId = "updateInsert",
InsertionMode = InsertionMode.Replace,
OnSuccess = "showUpdateInsertMessage",
OnFailure = "showUpdateInsertError"
@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.
Sirak Alemu 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
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[^].

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2017
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