You need not to pass data like current time from the controller. You can just write
<div>
@DateTime.Now
</div>
in your view. View rendered in the server then it will be render to the value of @DateTime.Now
.
Also, you can use ToString
method to format your view:
<div>
@DateTime.Now.ToString("yyyy.MM.dd")
</div>
will be rendered to
<div>
2016.06.14
</div>
Note that code will display server time that can be different to the client's timezone. To display current time you should use JS code.
It's not static data but it's also not really Model or business data and it can be calculated in the view without and input parameters. Message is also not a model and not controller-dependent data and it can be hardcoded in the view or retrieved from the model data:
<h3>Make a quiz Question here</h3>
If you need to pass data actually from the controller and its data is depend on internal state or input controller parameters or has other properties of "business data" you should use Model part from MVC pattern:
Model objects are the parts of the application that implement the
logic for the application's data domain. Often, model objects retrieve
and store model state in a database. For example, a Product object
might retrieve information from a database, operate on it, and then
write updated information back to a Products table in a SQL Server
database.
You can see details here or look to the Models and Validation in ASP.NET MVC part of Microsoft tutorial.
Add model class:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public int Zipcode { get; set; }
}
Pass model object to the view:
public ActionResult Index()
{
var model = GetModel();
return View(model);
}
Add strongly typed View via define model type:
@model Person
Use Model
variable in your view:
@Model.City