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
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
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