4
我使用視圖模型在asp.net mvc的3在哪裏放置在邏輯與MVC模式的視圖模型
在我來說,我有一個控制器,它發起連接到View一個視圖模型。
如果在URL中沒有附加變量DateForLookUp
,則控制器使用DateTime.UctNow初始化ViewModel,否則使用該變量。
我需要創建鏈接在視圖上。當用戶點擊鏈接時,我必須採取DateForLookUp
的值並添加或減去一天。
我的問題:
- 哪裏是合適的地方這個邏輯,ServiceLayer,視圖模型,控制器或查看?
VIEW
@Html.ActionLink("Next Day", "Daily")
@Html.ActionLink("Previous Day", "Daily")
控制器
public ActionResult Daily(string dateForLookUp)
{
DateTime dateTimeForLookUp;
if (string.IsNullOrWhiteSpace(dateForLookUp))
dateTimeForLookUp = DateTime.UtcNow;
else
dateTimeForLookUp = DateTime.Parse(dateForLookUp);
var eventsInDate = eventAggregateService.FindAllForDate(dateTimeForLookUp);
EventsAggregateDailyListViewModel eventDailyVM = new EventsAggregateDailyListViewModel();
eventDailyVM = new EventsAggregateDailyListViewModelBuilder().Build(eventDailyVM, dateTimeForLookUp);
return View(eventDailyVM);
}