locked
AJAX in MVC4 always replaces page RRS feed

  • Question

  • I'm trying to replace the content of a DIV using the @Ajax.ActionLink helper in Razor. The call works, and returns content, but always to a new page, removing my original page from the browser. My code is:

    Razor Partial Page:

    @Ajax.ActionLink("Replace Some Content","ReplaceMyContent", "KefaloniaSession",        new AjaxOptions { UpdateTargetId = "CHANGE-MY-CONTENT", HttpMethod = "GET" })

    <div id="CHANGE-MY-CONTENT" >

    </div>

    // MVC Controller Code:       

    [HttpGet]       

    public async Task<ActionResult> ReplaceMyContent ()       

    {           

    string subTotal = await RemoteWebService.GetSubTotalAsync();           

    return Content(subTotal);       

    } 

    I'm using VS2013, with the default MVC/WebAPI project template. I have installed the unobtrusive ajax library jquery.unobtrusive-ajax.js using NuGet.

    I'm seeing something similar with the Ajax BeginForm helper. I'd be grateful for clues...

    Colin Dixon

    • Moved by Mike Danes Friday, July 18, 2014 7:35 PM asp.net related
    Friday, July 18, 2014 5:09 PM

Answers

All replies