Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am facing Problem in getting Data From the Model in specified View, I have View Named Event and Same name of the Controller eventController, and here is an index Action Method, the view of This Action Method Need to Get DAta From The Controller but it Did not due to

following Line of Code
C#
public ActionResult Index()
       {
           HomeController pr = new HomeController();

           return View(pr.GetPrayer());
       }

This Line Says That This Method is returning GetPrayer Method and in View I am Passing Event Model to It. So this is the Problem,

Now Why I have Passed This GetPrayer Method to This index Action Method of the EventController, Because there is Control of The Prayer that Shows Prayer Timings, Etc. So if I did not Pass This GetPrayer to my EventController then it does not Show me prayer Control And Arise an Exception that Says "Object Ref did not set to an object" mean it does not have values of the Prayer that Need to be Rendered at the Event View.

Getrpayer Method is Writter as
C#
public List<Prayer> GetPrayer()
       {
           DateTime date = DateTime.Today;
           bool isSunrise = false;
           bool isSunset = false;
           DateTime sunrise = DateTime.Now;
           DateTime sunset = DateTime.Now;
           try
           {

               SunTimes.Instance.CalculateSunRiseSetTimes(new SunTimes.LatitudeCoords
                                      (39, 16, 19, SunTimes.LatitudeCoords.Direction.North),
                                                   new SunTimes.LongitudeCoords
                                      (76, 29, 41, SunTimes.LongitudeCoords.Direction.West),
                                                   date, ref sunrise, ref sunset,
                                    ref isSunrise, ref isSunset);
           }
           catch (Exception ex)
           {
               throw ex;
           }
           ViewData["sunSet"] = sunset.ToShortTimeString();
           ViewData["sunRise"] = sunrise.ToShortTimeString();
           List<Prayer> model = _cService.GetPrayerCollectionList(applicationID).ToList();
           return model;
       }

So what I should Do the Avoid this Problem, Mean to get Data From Event Model, And also Showing my Prayer Control through Returning GetPrayer from Index Action of Event Controller.

Looking Forward

Thank you

ALi
Posted

1 solution

Hi try this if could help.

C#
 List<prayer> model = new  List<prayer>();
 Prayer temp = new Prayer();
 temp.SunSet =  sunset.ToShortTimeString();
 temp.SunRise =  sunrise.ToShortTimeString();
 model.Add(temp)
 return model;
</prayer></prayer>



Please vote if could help...

Regards,
 
Share this answer
 
Comments
M Ali Qadir 12-Aug-12 6:14am    
hi, Thank you for replying but I have Done Some Different to make it happen,
For This i have Created a Class Of Prayer that holds both event and Prayer and Return Masjid from These explicit Methods, then I call Both of these Methods, and in Index Action of the Events I have Returned From the Index Action GetEvents() Method that was Casted in Masjid

and in View I have Make it @model CMg.Data.Masjid instead of Prayer same in events

Hope you all understand

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900