I am currently going nuts making a page to display the contents when an ID is passsed to it.
The code i have can be found below
@{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Home";
var db = Database.Open("StarterSite");
var PageID = UrlData[0];
if (PageID.IsEmpty()) {
PageID = "1";
}
var pages = db.QuerySingle("SELECT * FROM PAGES WHERE Id = @0",PageID);
}
<div class="productInfo">
<h3>@pages.Body</h3>
</div>
Basically what i am trying to get it to do is when you enter the url default/1 that the body of the page which has an id of 1 will appear and that if no querystring is given it will default to ID 1
When i run this i get an error with the line
@pages.Body
stating Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
the URL passed is http://localhost:20756/Default/1 and there is a page with an ID of 1 in the system
the exception in other words:
your runtime said:
if this code runs in your default.cshtml, try removing “Default/” from your url …
note that
PageID.IsEmpty()is not evaluating totruesinceUrlData[0]will probably contain"Default"