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 7008221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:42:25+00:00 2026-05-27T21:42:25+00:00

I am working on project using MVC 3.0(Razor framework). I am trying to get

  • 0

I am working on project using MVC 3.0(Razor framework). I am trying to get values from controller to view using Viewdata on Button click in Javascript Method.Its coming on document.ready but not on Button click.So please help to get the viewdata value on button click.

Following is my code

     [HttpPost]
            public ActionResult Update()
            {
                ViewData["myInfo"] = "my info";
                return View();
             }

And my JAvascript code:

    <script type="text/javascript">
        $(document).ready(function () {
            $("#btn").click(function () {

                $.post("/ImportCSV/Update", {},
               function ()
                {
                var g = '@ViewData["myInfo"]';

                });
                });
                });
    </script>

I want to show Viewdata value on button click

  • 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-27T21:42:25+00:00Added an answer on May 27, 2026 at 9:42 pm

    You’d better return a JSON result in this case. ViewData is bad. Don’t use it. In your case it doesn’t work because you need to define a corresponding view of this controller action that will interpret the ViewData and it is the final HTML fragment that you will get in the AJAX success callback. Using JSON you can directly send some data to the calling script:

    [HttpPost]
    public ActionResult Update()
    {
        return Json(new { myInfo = "my info" });
    }
    

    and then send an AJAX request to this controller action:

    <script type="text/javascript">
        $(document).ready(function () {
            $("#btn").click(function () {
                var url = @Url.Action("Update", "ImportCSV");
                $.post(url, {}, function (result) {
                    var myInfo = result.myInfo;
                    alert(myInfo);
                });
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on MVC project and i using jQuery in view page to get
I am trying to get the localization for my MVC project working with our
Inspired by the MVC storefront the latest project I'm working on is using extension
I am working on a project using .Net mvc. I have a csharp class
I'm working on an ASP MVC project using C#. My question is basically which
I'm currently working on an MVC 3 project using Ninject as my DI, the
I am working with an ASP.NET MVC project which was originally started from the
FYI, I'm working on my first MVC web application using MVC 3 and Razor
While working on a Spring 3 MVC project using Hibernate, we encountered an annoying
I'm working on an ASP.NET MVC project using jQuery. I'm referencing the jQuery VSDoc

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.