Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 927449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:51:24+00:00 2026-05-15T19:51:24+00:00

I have the following code in my post action method for Edit. JobCardService.Update(viewData.JobCard); var

  • 0

I have the following code in my post action method for Edit.

            JobCardService.Update(viewData.JobCard);
            var js = new JavaScriptSerializer();
            ViewData["Notifications"] = js.Serialize(new {NoteificationType = "Success", Message = "The installtion was successfully updated"});
            return RedirectToAction("Index");

However, on the client, ViewData is null/empty, i.e. this client code

var notifications = eval("<%= ViewData["Notifications"]%>");

renders as

var notifications = eval("");

I’m sure I’m doing something small wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:51:25+00:00Added an answer on May 15, 2026 at 7:51 pm

    ProfK – I think (as you’ll no doubt be aware) you’ll have to parse that json result in javascript once you get into your index view via the redirect. the jquery .getJson() method would seem most appropriate: http://api.jquery.com/jQuery.getJSON/

    Also, as you’re doing a RedirectToAction, then the context of the ViewData will be lost. In that case, you want to use TempData as a drop in replacement. Below is an example of what you could try:

    jim

    [edit] – not sure if this would work:

    // in the controller
    TempData["Notifications"] = js.Serialize(...);
    
    // in the index view
    function getMyJsondata() {
        var json = $.getJson('<%=ViewContext.TempData["Notifications"] %>');
    }
    

    or as per your amendment to the question, try this:

    // alternative in index view
    eval("(" + "<%= TempData['Notifications']%>" + ")"); 
    

    give it a go…

    adendum:
    to quote from a previous SO question on Tempdata vs ViewData: What is TempData collection used for in asp.net MVC?

    TempData is used to share data between
    controller actions. If your controller
    does a RedirectToAction and the target
    action needs data (perhaps a
    particular model instance) to act
    upon, you can store this data in
    TempData. Using TempData is similar to
    storing it in the session, but only
    for one round-trip. You use TempData
    when you need to pass data to another
    controller action rather than a view
    for rendering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: [AcceptVerbs(HttpVerbs.Post), Authorize(Roles = RoleKeys.Administrators)] public ActionResult Edit(int id, FormCollection
I have the following code which works just fine when the method is POST,
in the form action i have the following line\ <form action={URL} method=post target=_self id=xxx
I have the following form <form id=myform method=post action=#> <div class=fields> <fieldset class=ui-widget ui-widget-content
I have the following code snippet: Action<IProbingErrorHandler> handlerAction = x => x.Post(sourceContext, channelId, probingError);
I have the following code: // // POST: /PlayRoundHole/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection collection)
I have the following code: $postcode = $form->createElement('text', 'postcode'); $postcode->setLabel('Post code:'); $postcode->addValidator('regex', false, array('/^[a-z]{1,3}[0-9]{1,3}
I have the following code: public void post(String message) { final String mess =
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have the following code that works on PHP5 to send a HTTP POST

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.