i am working/tweaking the default install of asp.net mvc 4 .. added some views ..
and when i try to pass a model to my view, that model (name and namespace) gets written out to page.
@Model Blah.Web.UI.Models.DirectoryModel
@{
ViewBag.Title = "Directory";
Layout = "~/Views/Shared/_Layout.cshtml";
}
when i view my page, i see
Blah.Web.UI.Models.DirectoryModel Blah.Web.UI.Models.DirectoryModel
written out twice at the top of the page..
my controller just initializes the model and passes it inside the view..
also i noticed that this happens within @RenderBody() called form _layout.. so i am assuming it is done somewhere in my view..
even if i comment out all code on my view (accept the declaration above) i still see this string written out.
Change
to
The
@modeldirective with lower casemtells razor what is the type of the model.On the other hand
@Modelwith upper caseMjust callsToStringon the view’sModelproperty and writes the string in the response.That is why
Ouptuts:
Blah.Web.UI.Models.DirectoryModel Blah.Web.UI.Models.DirectoryModelFirst it writes the the
ToStringof theModeland the rest of the lineBlah.Web.UI.Models.DirectoryModelas plain text.