In asp.net mvc 5 there is a values on page, that user is entered or somehow it calculated by javascript. I need to put it in Html.BeginForm in section TO and FROM. The code sample is below:
MyPage.cshtml
<input id="datepickerFrom" value="31/12/2017" title="datepicker" />
<input id="datepickerTo" value="30/06/2018" title="datepicker" />
@using (Html.BeginForm("ExportToExcel", "DashBoard", new inputDates { from = "", to = "" }, FormMethod.Post))
{
<input type="submit" value="Export to Excel" class="button" />
}
Controller.ActionName
public ActionResult ActionName(inputDates dates)
{
//some actions
return new HttpStatusCodeResult(555, "Everything is OK");
}
Class inputDates
public class inputDates
{
public DateTime? from { get; set; }
public DateTime? to { get; set; }
}
I found a lot of answers that are using Model, but my values a are not from model. I don't know how to take values from html element or javascript values.
Thank you for help.
nameattributes to match the model properties (i.e.name="from"etc). And yournew inputDates { from = "", to = "" }in theBeginForm()make no sense (delete that)BeginFormoverload doesn't makes sense (see here). Use viewmodel properties and other helpers to pass those required elements.