This is a migrated thread and some comments may be shown as answers.

MVC - AJAX postback access values in Controller

1 Answer 195 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 29 Sep 2013, 09:27 PM
I'm not sure if I'm posting in the right place....

We're using KendoUI MVC with the help wrappers.

I have a simple page created in MVC using KendoUI.

The controller sets the value of a global variable "SomeValue" on initialization, but what I don't understand is when I use AJAX binding to bind data from the controller to the grid, why when "GetData()" is called it is unable to see the value of "SomeValue" or even the value of ViewBag.Heading.

When GetData() is called its almost as if the function is being called in isolation and doesn't know anything about the anything else in the controller....

What I wanted to do was when the Index controller is called, load all my data from my database into a global variable, so when "GetData()" is called it doesn't have to reload the data from the database, it can use the data that is set to the variable "SomeValue"....

How do you do this in KendoUI?

Here is a snippet of code of what I'm trying to do....


Controller
--------------
public string SomeValue;

public ActionResult Index(string strClient, string strProductType, string strCloseOfBusinessDate)
{
    ViewBag.Heading = "DV01";

    SomeValue = "Hello there!";

    return View();
}

public ActionResult GetData(string strClientName, string strDate)
{
    return Json(Graph.GraphData(SomeValue, strClientName, strDate));
}

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 01 Oct 2013, 02:52 PM
Hello William,


Your question is not related to KendoUI, you can search for tutorial on the internet how MVC works and why controllers are each time re-created for each request.

http://stackoverflow.com/questions/5425920/asp-net-mvc-controller-created-for-every-request


Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
William
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or