从模型到视图提取数据时遇到问题 [英] Having problem in extracting data from Model to View
问题描述
我在指定视图中从模型获取数据时遇到问题,我具有名为事件的视图和控制器eventController的相同名称,这是一个索引操作方法,该操作方法的视图需要从控制器获取DAta,但它不是由于
遵循以下代码行
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());
}
此行表示此方法正在返回GetPrayer方法,并且在视图中,我正在将事件模型传递给它.这就是问题,
现在,为什么我已将此GetPrayer方法传递给EventController的该索引操作方法,因为存在对祷告进行控制的控件,该控件显示了祷告时间等,因此,如果我没有将此GetPrayer传递给EventController,那么它将不会向我显示祷告控制并出现一个异常,说对象引用未设置为对象",表示它不具有需要在事件视图中呈现的祷告"的值.
Getrpayer方法很糟糕
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;
}
因此,我该怎么做才能避免此问题,这意味着从事件模型中获取数据,并通过从事件控制器的索引操作返回GetPrayer来显示我的祷告控制.
展望
谢谢
ALi
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
推荐答案
如果可以的话,尝试一下.
Hi try this if could help.
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,
这篇关于从模型到视图提取数据时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!