1

I have creatd a partial view and inside it I am using AJAx.BeginForm. In Post Edit Action Method, I am adding VIEWDATA Like this

        if (ModelState.IsValid)
        {
            service.SaveAccount(account);
            TempData["message"] = "Account has been updated successfully!";

            AccountInfo accountInfo = new AccountInfo();
            accountInfo.AccountStatuses = service.GetAccountStatuses();
            accountInfo.AccountTypes = service.GetAccountTypes();
            accountInfo.CreditTerms = service.GetCreditTerms();
            return View("DisputeSubscriber", accountInfo);

        }
        else
        {
            return PartialView("_UpdateAccountDetails", account);
        }

and redirecting to same partial view. In partial view, I have added like this:

 @if (TempData["message"] != null)
                    {
                        <div class="Message">
                           I am here.
                            @TempData["message"]
                        </div>
                    }

but this message is not shows. this message is also inside AJAX.BeginForm. Please suggest

Do I need to redirect main view instead of partial view or there is something I am missing

DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

1 Answers1

0

You seem to be using TempData and not ViewData which is not quite the same. Also you mentioned that you are using an Ajax.BeginForm to invoke this controller action. Since this is an AJAX call make sure that you have specified an UpdateTargetId in your AjaxOptions so that the resulting partial is injected somewhere into the DOM:

@using (Html.BeginForm(new AjaxOptions { UpdateTargetId = "foo" }))
{
    ...
}

<div id="foo"></div>
Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I have used UpdateTargetId as well but it is not showing the div. I see that record is updated. I used alert and it shows error alert. "@using (Ajax.BeginForm("UpdateAccountDetails", new AjaxOptions { OnSuccess = "alert('done')", OnFailure = "alert('Error');" }))" – DotnetSparrow Nov 09 '11 at 07:23
  • @DotnetSparrow, is the element updated after all when you used UpdateTargetId? I am not talking about the TempData issue. Put some dummy data in the partial and make sure it updates first. – Darin Dimitrov Nov 09 '11 at 07:25
  • Can you please give an example of how to update targetid >? I just set updateTargetId to my div which i want to update – DotnetSparrow Nov 09 '11 at 07:30
  • @DotnetSparrow, my answer has an example of that. – Darin Dimitrov Nov 09 '11 at 07:31
  • In your example, what value be set to foo div ? – DotnetSparrow Nov 09 '11 at 07:33
  • @DotnetSparrow, the foo div is only a placeholder into which will be injected the result of the AJAX call : the partial. – Darin Dimitrov Nov 09 '11 at 07:34
  • will it be done automatically done ? In my case I have a partialview which onsuccess shows same partial view with success message or error message – DotnetSparrow Nov 09 '11 at 07:36