Guys, I am a little confused with the usage of the keyword model/Model in MVC, so I was hoping somebody could clarify a few aspects of it (needless to say internet searches didn't really help that much).
Given this model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Ebuy.Website.Tests.Models
{
public class Auction
{
public long Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public decimal StartPrice { get; set; }
public decimal CurrentPrice { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
}
And this method in a Auction controller
public ActionResult Details(long id = 0)
{
var auction = new Auction
{
Id = id,
Title = "Brand new Widget 2.0",
Description = "This is a brand new version 2.0 Widget!",
StartPrice = 1.00m,
CurrentPrice = 13.40m,
// StartTime = DateTime.Parse("6-15-2012 12:34 PM"),
// EndTime = DateTime.Parse("6-23-2012 12:34 PM"),
StartTime = DateTime.Parse( "6-15-2012 12:34 PM", CultureInfo.CreateSpecificCulture("en-EN") ),
EndTime = DateTime.Parse( "6-23-2012 12:34 PM", CultureInfo.CreateSpecificCulture("en-EN") ),
};
return View(auction);
}
and finally a Create view:
@model Ebuy.Website.Tests.Models.Auction
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
<p>
@Html.LabelFor(model => model.Title)
@Html.EditorFor(model => model.Title)
</p>
...
}
1)when model is used at the top of a view as in @model Ebuy.Website.Tests.Models.Auction
, it is pretty clear, in the sense that it's there because that is a strongly typed view and it allows to use property of the class without fully qualifying them;
2)Not so clear when it is used in the lambda expressions: @Html.LabelFor(model => model.Title)
. What's model
in here? What does it stand for?
3)I have also seen Model
used somewhere other than in Ebuy.Website.Tests.Models.Auction
, but for the life of me I can't find it now. Any idea what Model stands for?
I mean my understanding is that model
is nothing else than the model class, or rather an instance of the class that gets passed over for processing, is that correct?
cheers