views:

55

answers:

2

I have a new MVC 2 site that has been working fine on my local box but has a path issue when published to an IIS 7.5 server. The site pulls up fine, navigation links such as

<ul id="menu">              
      <li><%: Html.ActionLink("Home", "Index", "Home")%></li>
      <li><%: Html.ActionLink("Search", "Index", "Search")%></li>
      <li><%: Html.ActionLink("Help", "About", "Home")%></li>

work just fine. However, when trying to load a partial view with jQuery via code like this

<p>
    <input type="submit" value="Search Alumni Directory" onclick='loadSearchResults( )' />
</p>

<script type="text/javascript">

    function loadSearchResults(val) {

        var formData = $("#search-form").serializeArray(); // muy importante

        $('div.search-results').load('/Search/LoadResults/', formData, function () {
            $('div.search-results-pending').show().delay(1000).hide(500);
            $('div.search-instructions').hide();
            $('div.search-results').show('slow');
         });

    }

</script> 

I get a 404 error because the path is

http://test-alumni.indiana.edu/Search/LoadResults

instead of

http://test-alumni.indiana.edu/OnlineDirectory/Search/LoadResults

adding '/OnlineDirectory' to the path in my load function solves the problem but it does not seem like I should have to do this. I am publishing to a directory that is configured as an application. Any thoughts?

+1  A: 

That's because the browser is resolving the "/" path based on the hostname, test-alumni.indiana.edu. If your page is relative to /OnlineDirectory, try it without the "/" in front of "Search".

Derrick
Thanks Derrick for the simple solution!
indyDean
+1  A: 
function loadSearchResults(val) {

    var formData = $("#search-form").serializeArray(); // muy importante
    var url = '<%: Url.Action("LoadResults,"Search")%>';
    $('div.search-results').load(url, formData, function () {
        $('div.search-results-pending').show().delay(1000).hide(500);
        $('div.search-instructions').hide();
        $('div.search-results').show('slow');
     });

}
Gregoire
Thanks Gregoire, this works
indyDean