ビュー モデル:
namespace AESSmart.ViewModels
{
public class HomeIndexViewModel
{
public power_weatherstationhistory WeatherStationHistory {get;set;}
public DateTime startingDate {get;set;}
public DateTime endingDate {get;set;}
public DateTime utcStartingDate {get;set;}
public DateTime utcEndingDate {get;set;}
public double LifeTimeGeneration {get;set;}
public double CO2Offset {get;set;}
public double GallonsOfGasolineOffset {get;set;}
public double BarrelsOfOilOffset {get;set;}
public string Message {get;set;}
}
}
コントローラ:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using AESSmart.Models;
using AESSmart.ViewModels;
namespace AESSmart.Controllers
{
public class HomeController : Controller
{
private readonly AESSmartEntities db = new AESSmartEntities();
public ActionResult Index()
{
HomeIndexViewModel IndexViewModel = new HomeIndexViewModel();
if (Convert.ToString(IndexViewModel.startingDate) ==
"1/1/0001 12:00:00 AM" ||
Convert.ToString(IndexViewModel.endingDate) ==
"1/1/0001 12:00:00 AM")
{
IndexViewModel.startingDate =
new DateTime(DateTime.Now.Year,
DateTime.Now.Month,
DateTime.Now.Day,
0,
0,
0);
IndexViewModel.endingDate =
new DateTime(DateTime.Now.Year,
DateTime.Now.Month,
DateTime.Now.Day,
23,
59,
59);
}
// There is a bunch of code here to gather all of the
// data need and modify the values of IndexViewModel
return View(IndexViewModel);
}
}
}
私のインデックスページは次のものを使用しています:@model AESSmart.ViewModels.HomeIndexViewModel
次に@Model.Something
、ビュー内の各ピースをレンダリングするために使用します。
ビューで使用される、表示する必要があるデータがたくさんあります。ユーザーが変更できるデータは、startingDate
とのみEndingDate
です。それらのいずれかを変更したら、Index
ActionResult
それらHomeController
の新しい日付を使用して正しい情報を取得する必要があります。現在、デフォルトで同じ日付に戻っています(その日付は今日の日付です)。ここで何が間違っていますか?
また、Index
ActionResult
は気象情報を収集します。収集した情報を実際にデータベースに保存したい。に含まれる情報を保存するにはどうすればよいWeatherStationHistory
ですか?
ユーザーに表示されるサンプルは次のとおりです。