Well, based on the link you provided in your comment in a prior answer, you're using ASP.Net WebPages
- which is a great lightweight way of getting an ASP.Net site up using Razor syntax. It's not however MVC
so for one thing you won't have things like ViewData
, but that's ok - you can use Page
or PageData
.
This would be how an entire page would look like (though typically you'd use _layout
file in combination with "content files"):
@using Newtonsoft.Json;
@using System.Net;
@using System.IO;
@{
/*
Page or PageData instead of ViewBag/ViewData
*/
Page.Title = "Hello World"; //this is typically used with a _layout.cshtml where the<title> Tag would be
//You can create/name Page properties/data as needed
Page.Whatever = "whatever I want";
Page.H1TagForSeo = "this is the h1 tag";
Page.SomeInteger = 100;
Page["MyPageData"] = DateTime.UtcNow;
List<string> files = new List<string>();
if (IsPost)
{
//IsPost test - this will only run if this page is requested via POST
for (int i = 0; i < 10; i++)
{
files.Add(i.ToString());
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>@Page.Title</title>
</head>
<body>
<h1>@Page.H1TagForSeo</h1>
<p>The time is @Page["MyPageData"]</p>
<p>
You can use <code>@@Page propertes/data similar to ViewBag/ViewData</code> @Page.Whatever was viewed @Page.SomeInteger times
</p>
@if (IsPost)
{
<div>Post Test</div>
<p>This entire section will only be displayed when requested via POST</p>
<p>@string.Join(",", files)</p>
}
</body>
</html>
Hth...