I want to employ clean URL's - at the moment this is my code for a webpage I am toying with:
@{
var id=Request["id"];
var SQLSELECT = "SELECT * FROM topicDetails where ID=@0";
var db = Database.Open("MySite");
var Topic = db.QuerySingle(SQLSELECT,id);
var TopicHeader=Topic.Header;
var TopicDetails=Topic.Details;
}
<h1>@Subject.Header</h1>
<p>@Html.Raw(@Subject.Details)</p>
You must be generating the URL with the querystring somewhere, so instead of adding a querystring, generate it like this:
var id=Request["id"];
/subject/@id
Then in your code, the value of id can be retrieved using UrlData[0]
Relatively easy - I was on the right track, just overcomplicated a simple issue I guess.
var id=Request["id"];
With this:
var id=UrlData[0].AsInt();
On the back of that though I had issues with all my CSS not working, which was a matter of adding the @Href("~/blah") in a few places.. Thanks again for your help Mike!
Dont forget to Mark as Answer if it has solved your problem!
Marked as answer by a-rad on Apr 27, 2011 12:40 PM
a-rad
Member
451 Points
169 Posts
Quick question about Clean URLs
Apr 17, 2011 04:23 AM|LINK
Hey guys,
I am relatively new to the Razor syntax and I just need a quick clarification on something that is covered in this tutorial: http://www.asp.net/webmatrix/tutorials/18-customizing-site-wide-behavior
I want to employ clean URL's - at the moment this is my code for a webpage I am toying with:
@{ var id=Request["id"]; var SQLSELECT = "SELECT * FROM topicDetails where ID=@0"; var db = Database.Open("MySite"); var Topic = db.QuerySingle(SQLSELECT,id); var TopicHeader=Topic.Header; var TopicDetails=Topic.Details; } <h1>@Subject.Header</h1> <p>@Html.Raw(@Subject.Details)</p>The URL I go to looks like this at the moment: http://localhost:2421/subject.cshtml?id=1 and I want to replace with http://localhost:2421/subject/1
I have a feeling I need to use UrlData in there to establish what is being requested but unsure how to code it in.. Any help would be appreciated :)
Mikesdotnett...
All-Star
155645 Points
19985 Posts
Moderator
MVP
Re: Quick question about Clean URLs
Apr 17, 2011 10:53 AM|LINK
You must be generating the URL with the querystring somewhere, so instead of adding a querystring, generate it like this:
/subject/@id
Then in your code, the value of id can be retrieved using UrlData[0]
Web Pages CMS | My Site | Twitter
a-rad
Member
451 Points
169 Posts
Re: Quick question about Clean URLs
Apr 17, 2011 03:59 PM|LINK
Relatively easy - I was on the right track, just overcomplicated a simple issue I guess.
With this:
On the back of that though I had issues with all my CSS not working, which was a matter of adding the @Href("~/blah") in a few places.. Thanks again for your help Mike!