Quick question about Clean URLshttp://forums.asp.net/t/1673422.aspx/1?Quick+question+about+Clean+URLsSun, 17 Apr 2011 15:59:20 -040016734224385873http://forums.asp.net/p/1673422/4385873.aspx/1?Quick+question+about+Clean+URLsQuick question about Clean URLs <p>Hey guys,<br> <br> I am relatively new to the Razor syntax and I just need a quick clarification on something that is covered in this tutorial:&nbsp;<strong><a href="http://www.asp.net/webmatrix/tutorials/18-customizing-site-wide-behavior">http://www.asp.net/webmatrix/tutorials/18-customizing-site-wide-behavior</a>&nbsp;<br> <br> </strong>I want to employ clean URL's - at the moment this is my code for a webpage I am toying with:<br> <br> <pre class="prettyprint">@{ var id=Request[&quot;id&quot;]; var SQLSELECT = &quot;SELECT * FROM topicDetails where ID=@0&quot;; var db = Database.Open(&quot;MySite&quot;); var Topic = db.QuerySingle(SQLSELECT,id); var TopicHeader=Topic.Header; var TopicDetails=Topic.Details; } &lt;h1&gt;@Subject.Header&lt;/h1&gt; &lt;p&gt;@Html.Raw(@Subject.Details)&lt;/p&gt;</pre> </p> <p>The URL I go to looks like this at the moment:&nbsp;<strong><a href="http://localhost:2421/subject.cshtml?id=1">http://localhost:2421/subject.cshtml?id=1</a>&nbsp;</strong>and I want to replace with&nbsp;<strong><a href="http://localhost:2421/subject.cshtml?id=1">http://localhost:2421/subject/1</a></strong></p> <p>I have a feeling I need to use <strong>UrlData </strong>in there to establish what is being requested but unsure how to code it in.. Any help would be appreciated :)</p> <p><strong><br> </strong></p> 2011-04-17T04:23:28-04:004386093http://forums.asp.net/p/1673422/4386093.aspx/1?Re+Quick+question+about+Clean+URLsRe: Quick question about Clean URLs <p>You must be generating the URL with the querystring somewhere, so instead of adding a querystring, generate it like this:</p> <p>/subject/@id</p> <p>Then in your code, the value of id can be retrieved using UrlData[0]</p> <p>&nbsp;</p> 2011-04-17T10:53:43-04:004386282http://forums.asp.net/p/1673422/4386282.aspx/1?Re+Quick+question+about+Clean+URLsRe: Quick question about Clean URLs <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Mikesdotnetting</h4> <p></p> <p>You must be generating the URL with the querystring somewhere, so instead of adding a querystring, generate it like this:</p> <pre class="prettyprint">var id=Request[&quot;id&quot;];</pre> <p> /subject/@id</p> <p>Then in your code, the value of id can be retrieved using UrlData[0]</p> <p></blockquote></p> <p>Relatively easy - I was on the right track, just overcomplicated a simple issue I guess.&nbsp; </p> <pre class="prettyprint">var id=Request[&quot;id&quot;];</pre> <p> With this:</p> <pre class="prettyprint">var id=UrlData[0].AsInt();</pre> <p>On the back of that though I had issues with all my CSS not working, which was a matter of adding the @Href(&quot;~/blah&quot;) in a few places.. Thanks again for your help Mike!</p> </blockquote> 2011-04-17T15:59:20-04:00