This is a migrated thread and some comments may be shown as answers.
Going to different page causes view data to become null
1 Answer 26 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 1
John asked on 13 Oct 2010, 09:53 PM
Hi, im using ASP.NET MVC 2 with a Telerik Grid. The grid itself displays the data well enough, and i am using server binding. When i try to go to a different page, Ive discovered that my view data nulls itself.

Here is the databinding part of my grid:
<code> DataBinding(d => d.Server().Select("Index", "Manifest", new {mivm = (ManifestIndexViewModel)ViewData["ManifestIndexSearchModel"], id = -3, postback = 0})) </code>

And the controller action is:
<code>
public ActionResult Index(ManifestIndexViewModel mivm, int id = 0, int postback = 0)
        {
            var fromDt = mivm.FromDate ?? new DateTime(1900, 1, 1);
            var toDt = mivm.ToDate ?? new DateTime(2099, 12, 31);

            mivm.DetermineSearchParam();

            switch (id)
            {
                case -3:
                    break;
                case -2:
                    //Field offices changed
                    mivm.FacilityId = 0;
                    break;
                case -1:
                    mivm.FieldOfficeId = 0;
                    mivm.FacilityId = 0;
                    //Company changed)
                    break;
                case 0:
                    //First time on screen
                    mivm = new ManifestIndexViewModel("",
                                                      0,
                                                      0,
                                                      0,
                                                      new DateTime(1900, 1, 1),
                                                      new DateTime(2099, 12, 31),  
                                                      _icdp.GetAllCompanies(),
                                                      _ifodp.GetAllFieldOffices(),
                                                      _ifdp.GetAllFacilities());
                    break;
                case 1:
                    if (mivm.ManifestPartialId == "" &&
                   mivm.CompanyId == 0 && mivm.FieldOfficeId == 0 && mivm.FacilityId == 0 &&
                   fromDt == new DateTime(1900, 1, 1) && toDt == new DateTime(2099, 12, 31))
                        {
                            id = 0;
                        }
                    else
                    {
                        mivm.Manifests = _imdp.GetManifestByViewModel(mivm);
                    }
                    break;
                default:
                    break;
            }

            //Will always have to reset the lists.
            mivm.Companies = _icdp.GetAllCompanies();
            mivm.FieldOffices = _ifodp.GetFieldOfficesForCompany(mivm.CompanyId);
            mivm.Facilities = _ifdp.GetFacilityForFieldOffice(mivm.FieldOfficeId);

            ViewData["ManifestIndexSearchModel"] = mivm ?? null;

            return View(mivm);
        }
</code>

I cant quite track the problem. Any insights?

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Oct 2010, 07:29 AM
Hello John,

 What happened when you put a break point in the Index method? Did it get hit? I tried a simpler setup but ViewData was correctly populated. I am sending my test project as attachment.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or