By means of several alternatives, an example is shown below by sending information from controller
to its referent 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>