<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chillijam.co.uk &#187; tips</title>
	<atom:link href="http://chillijam.co.uk/tag/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://chillijam.co.uk</link>
	<description></description>
	<lastBuildDate>Thu, 28 Jan 2021 10:32:11 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>ASP.NET MVC &#8211; Preparing for the real world</title>
		<link>http://chillijam.co.uk/2009/05/11/aspnet-mvc-preparing-for-the-real-world/</link>
		<comments>http://chillijam.co.uk/2009/05/11/aspnet-mvc-preparing-for-the-real-world/#comments</comments>
		<pubDate>Mon, 11 May 2009 10:46:04 +0000</pubDate>
		<dc:creator><![CDATA[Marc]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://chillijam.co.uk/?p=236</guid>
		<description><![CDATA[This is the first in a series of posts about things I found out while learning ASP.NET MVC. Today : adding jQuery support that will work wherever the app is deployed in a directory structure. In order to reference the jQuery javascript files, I had to figure out how to add a realtive link to &#8230; <a href="http://chillijam.co.uk/2009/05/11/aspnet-mvc-preparing-for-the-real-world/" class="more-link">Continue reading <span class="screen-reader-text">ASP.NET MVC &#8211; Preparing for the real world</span> <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>This is the first in a series of posts about things I found out while learning ASP.NET MVC.  Today : adding jQuery support that will work wherever the app is deployed in a directory structure.</p>
<p>In order to reference the jQuery javascript files, I had to figure out how to add a realtive link to the .js files that would work even if the app was deployed to an unknown virtual directory.  A quick question on <a href="http://stackoverflow.com">StackOverflow.com</a> led me to the following steps.</p>
<p>1) Create an extension method in the Helpers namespace&#8230;</p>
<pre class="brush: csharp; title: ; notranslate">public static string GetBasePath(this HtmlHelper helper)

{

    var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);

    return urlHelper.Content(&quot;~/&quot;);

}</pre>
<p>Next, point the link tags for my js file to the new location&#8230;</p>
<pre class="brush: jscript; title: ; notranslate">&lt;script src=&quot;&lt;%= Html.GetBasePath() %&gt;Scripts/jquery-1.3.2.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
 </pre>
<p>That&#8217;s it.  All I had to do.</p>
<p>Of course, since I want to call data back from my MVC site via jQuery, I had to take a couple of extra steps to make the base path available to my scripts.  Back in my master page, I created the following snippet.</p>
<pre class="brush: jscript; title: ; notranslate">&lt;script language=&quot;javascript&quot;&gt;

  var rootUrl = &quot;&lt;%= Html.GetBasePath() %&gt;&quot;; 

&lt;/script&gt;</pre>
<p>Now I can call the data back from the site within my custom-defined jQuery script as follows&#8230;</p>
<pre class="brush: jscript; title: ; notranslate">$('#preview').click(function() {

    $.get(rootUrl + &quot;jquery/getprovider/&quot; + $(this).attr(&quot;name&quot;), function(data) { $('#detailDiv').slideDown(300); $('#detailDiv').html(data); });

    });</pre>
<p>My #preview object has an id coded into its &#8216;name&#8217; attribute so the jQuery controller can reference the correct data., eg.</p>
<pre class="brush: xml; title: ; notranslate">&lt;a href=&quot;#&quot; name=&quot;12345&quot;&gt;details&lt;/a&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://chillijam.co.uk/2009/05/11/aspnet-mvc-preparing-for-the-real-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
