Reputation: 31
i have two text boxes for from date and to date , i want to add two more text boxes for hrs:min, how to add two more text boxes and pass the values into my controlller so that i can filter the records according to the date as well as time.
view
<span style="float:left; padding:10px;">Ftom Date : </span><input type="text" name="fromDate" value="@(ViewBag.FromDate != null ? Convert.ToDateTime(ViewBag.FromDate).ToString("dd/MM/yyyy") : "")" class="form-control datetime" id="txtFromDate" style="float:left; width:100px;" />
<span style="float:left; padding:10px;">HRS : </span><input type="text" name="FromHrs" value="" class="form-control datetime" id="txtFromDate" style="float:left; width:50px;" placeholder="Hrs" /><input type="text" name="FromMin" value="" class="form-control datetime" id="txtFromDate" style="float:left; width:50px;" placeholder="Min" />
<span style="float:left; padding:10px;">To Date : </span><input type="text" name="toDate" value="@(ViewBag.ToDate != null ? Convert.ToDateTime(ViewBag.ToDate).ToString("dd/MM/yyyy") : "")" class="form-control datetime" id="txtToDate" style="float:left; width:100px;" />
<span style="float:left; padding:10px;">HRS : </span><input type="text" name="ToHrs" value="" class="form-control datetime" id="txtFromDate" style="float:left; width:50px;" placeholder="Hrs" /><input type="text" name="ToMin" value="" class="form-control datetime" id="txtFromDate" style="float:left; width:50px;" placeholder="Mins" />
<span style="float:left; padding:10px;">Device : </span>
@using (Html.BeginForm("Index", "SignalTesting", FormMethod.Post, new { enctype = "multipart/form-data", id = "form" }))
{
<div>
<span >Ftom Date : </span><input type="text" name="fromDate" value="@(ViewBag.FromDate != null ? Convert.ToDateTime(ViewBag.FromDate).ToString("dd/MM/yyyy") : "")" class="form-control datetime" id="txtFromDate" />
<span>To Date : </span><input type="text" name="toDate" value="@(ViewBag.ToDate != null ? Convert.ToDateTime(ViewBag.ToDate).ToString("dd/MM/yyyy") : "")" class="form-control datetime" id="txtToDate" />
<span >Device : </span>
<select id="ddlDevices" name="DeviceID" class="form-control" >
...
</select>
<input type="submit" value="Submit" class="btn btn-default" />
</div>
}
</div>
controller
private AssetTracker getAssetDetails(string deviceID,int FHrs,int ToHrs,int FromMin,int ToMin, DateTime? fromDate = null, DateTime? toDate = null)
{
int Fromhours = FHrs;
int Tohours = ToHrs;
int From_min = FromMin;
int To_min = ToMin;
var items = Pirs.Where(a => !a.dataFrame.EndsWith("AAAAAAAAAAA=") && (fromDate == null || fromDate.Value.Date <= TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp), TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Date) && (toDate == null || toDate.Value.Date >= TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp), TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Date) && TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp), TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Hour >= Fromhours && TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp), TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Hour <= Tohours
&& TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp), TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Minute >= From_min && TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp), TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Minute <= To_min)
}
Upvotes: 2
Views: 54
Reputation: 8226
I am not sure if this is what you need.
Add the time input fields to your form:
<input type="text" id="fromTime" name="fromTime" />
<input type="text" id="toTime" name="toTime" />
Then update you controller to receive the new form values:
private AssetTracker getAssetDetails(string deviceID, DateTime? fromDate = null, DateTime? toDate = null, string fromTime, string toTime )
Upvotes: 1