ASP.NET MVC 4 - Display results on same page using AJAX RRS feed

  • Question

  • Hi

    It should not be a hard one…L I believe.

    I’m trying to load my search results after filling parameters* hitting submit button on the same page (view). I’m trying with AJAX form option.

    Here is the expected functionality

    • Fill input values
    • Click submit
    • Load results on the same page

    I’m using MVC 4 with Razor Engine

    The issue here is…

    Instead of loading the partial view within Parent view, Its replacing Parent view with Partial View. ie., Results are loading within DIV panel as a partial view…

    Have UnObstusive JS reference on my Layout file.

    Am I doing something wrong here. Any help will be appreciated. Thanks

    Code blocks…

    Parent  View (MyParentView.cshtml)

    @using (Ajax.BeginForm("Index", "MyController", new AjaxOptions


       UpdateTargetId = "divResults",

       InsertionMode = InsertionMode.Replace,

       HttpMethod = "POST"



    <input controls…goes here>

    <td align="left"><input type="submit" value="Go" /></td>   

    @if (ViewBag.showResult == true)


            <div id=" divResults ">

                  @Html.Partial("MyPartialView", Model)





    Partial View (MyPartialView.cshtml)

            //controls to display results 

    Controller Methods (MyController.cs)

        public ActionResult Index(MyModel model)


    //Load input parameters controls with default values

                 return View("MyParentView",model);



        public ActionResult Index (MyModel model)


         //Code goes here…


    if (ModelState.IsValid)


                    if (model.Count() != 0)


                        //if (Request.IsAjaxRequest())


                        ViewBag.showResult = true;

                        return PartialView("MyPartialView",model);






    Referred unobstusive ajax javascript file

    <script type ="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

    • Edited by GeekPeek Monday, November 12, 2012 8:45 PM Should move to different forum ?
    Monday, November 12, 2012 6:19 PM


  • Hi,

    This is dedicated WSP forum. for MVC related issue, I suggest you ask for help from development forum such as,

    where has the mvc sub forum. You will receive more professional and exact idea for your question.

    Thursday, November 15, 2012 3:45 AM