Search code examples
asp.net-mvcasp.net-mvc-ajax

how to update specific div data through ajax in asp.net mvc


how to update specific div data through ajax in asp.net mvc


Solution

  • You may take a look at the UpdateTargetId property:

    Controller:

    public ActionResult SomeAction()
    {
        // you could return a PartialView here if you need more complex HTML fragment
        return Content("<span>some content</span>", "text/html");
    }
    

    View:

    <div id="result"></div>
    <%= Ajax.ActionLink(
        "Update div test", 
        "SomeAction", 
        new AjaxOptions { UpdateTargetId = "result" }
    ) %>