Through the various alternatives below follows an example by sending the information of the controller
for your reference view
.
Class Model
public class Professor
{
public int Id { get; set; }
public String Nome { get; set; }
public DateTime DataInicial { get; set; }
public DateTime DataFinal { get; set; }
}
Actionresult
public ActionResult Pessoas()
{
DateTime Data = DateTime.Now;
return View(new Professor() { Id = 0, Nome = "Nome 1", DataInicial = Data, DataFinal = Data.AddDays(5) });
}
Page
@model WebApi.Models.Professor
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Pessoas</title>
</head>
<body>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Professor</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Nome, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Nome, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Nome, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataInicial, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataInicial, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DataInicial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataFinal, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataFinal, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DataFinal, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
</body>
</html>
Okay @Tiagocésaroliveira and in the view how do I place it? I would like it to be visible in the form that date
– PFVictor
@Pfvictor edited the answer.
– Tiago César Oliveira
Thanks for the answers. I can through them automatically record in the bank the return date as 5 days after the current date. And how do I get the return date 5 days after the date the user enters? (not necessarily the date of the day) Also the return date does not appear in the textbox, only saved in the bank. How do I make it visible automatically? Type, user type start date, automatically return date appears in text box? @Tiagocésaroliveira
– PFVictor
@Pfvictor, please edit your question with the full requirement.
– Tiago César Oliveira
Actually @Tiagocésaroliveira this is already in the question. I did not say that the initial date is current, but the date that the user type. But I improved it there. Thank you.
– PFVictor