views:

116

answers:

1

Hi

This is a really strange issue. I have developed a small MVC application and have done testing up until now using the VS2008 built in dev server and everything works as I expect. I have now moved the solution to IIS hosted and I see different results in a view which uses an Ajax.ActionLink.

The actionlink links to a controller action which returns a partial view (.ascx). In the AjaxOptions of the link I specify the UpdateTargetId of the DOM element that I wish the partial view returned by the action to replace. When running the application using the built in dev server, behaviour is as expected -> the ajax call successfully returns the partialview and replaces the specified DOM element. However when hosted in IIS, the controller action is successfully executed but the result is rendered on a new page rather than replacing the specifed DOM element.

Here is relevant source for the page which makes the ajax call:

<% if (info.CurrentStatus != OrderStatus.Received &&
              info.CurrentStatus != OrderStatus.Processing)
           { %>
                <td><%= Ajax.ActionLink("Reprocess Order", "Reprocess",
                            new { generatedId = info.GeneratedId },
                            new AjaxOptions
                            {
                                UpdateTargetId = "success" + info.GeneratedId,
                                OnSuccess = "reprocessSuccess"
                            })%></td>
        <% } %>

        <td><%= Html.Div("success" + info.GeneratedId) %> </td>

And here is the action which provides the partial view:

[RequiresSearch()]
public ActionResult Reprocess(string generatedId)
{
    if (RequestReprocessingOfOrder(generatedId))
    {
        ViewData["reprocessSuccess"] = "Reprocessing request successful. Order is queued for reprocessing";
    }
    else
    {
        ViewData["reprocessSuccess"] = "Reprocessing request failed. Please contact the administrator";
    }

    return PartialView();
}

Any help would be greatly appreciated!!!

EDIT: I don't have alot of mvc/ajax experience so am unsure as to where to event start to try and solve this, so even pointers of what to look for would be great.

+1  A: 

Okay so I have solved this problem, turned out to be caused by the src references I was using for the scripts the view required (in this case MicrosoftAjax.js and MicrosoftMvcAjax.js). The path I was using was no longer valid when hosted in IIS, so dynamically generating the path solved the issue.

Replace:

<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"/>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"/>

With:

<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js")%>" type="text/javascript"/>
<script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js")%>" type="text/javascript"/>

Silly mistake, but solution not obvious considering the symptoms.

Simon Fox