0

So i am using ajax.beginform to load the data and for some reason the results are loaded in a new page. everything ive read online leads me to believe its because im not including the right scripts but im struggling to figure out what im doing wrong. I even tried adding the script tags to the top of each view and the results were the same.

Here is my _Layout.cshtml

<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year - AL SE Tool</p>
    </footer>
</div>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

The Controller

    public ActionResult CheckCust(ClientCheckModels clientCheck)
    {
        CustomerInfo custInfo = new CustomerInfo(clientCheck.CustomerId);
        DataModel dataModel = custInfo.GetClientData();
       return PartialView("_ClientResults",dataModel);
    }

The main view

<div id="clientdata">
    @using (Ajax.BeginForm("CheckCust", "ClientCheck", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "clientdata", InsertionMode = InsertionMode.Replace }))
    {

        <div class="form-group">
            @Html.LabelFor(model => model.CustomerId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.CustomerId, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.CustomerId, "", new { @class = "text-danger" })
            </div>
        </div>
        <input type="submit" value="Submit" class="btn btn-default" />

    }
    <br /><br />
        @{Html.Partial("_ClientResults", Model);}
</div>

The partial view

@model SETools.Models.DataModel
<br />

@if(Model != null)
{ 
<h3>Threat Appliances<small>@Html.DisplayFor(model => model.ThreatManager.Appliances.Count)</small></h3>

<h3>Protected Hosts <small>@Html.DisplayFor(model => model.ThreatManager.ProtectedHosts.Count)</small></h3>
<h3>Hosts with Errors <small>@Html.DisplayFor(model => model.ThreatManager.HostErrors)</small></h3>
<h3>New Hosts <small>@Html.DisplayFor(model => model.ThreatManager.HostNew)</small></h3>
<h3>Ok Hosts <small>@Html.DisplayFor(model => model.ThreatManager.HostOk)</small></h3>
<h3> 
<rest removed to shave space>
user961346
  • 301
  • 2
  • 3
  • 17
  • Where is the DOM element with `id="clientdata" (the element to update with the data)? –  Sep 16 '14 at 21:56
  • right above the ajax.beginform statement.Once the form is submitted i want to render the partial view below the submit button – user961346 Sep 17 '14 at 01:29
  • In that case, you should have `
    ` just below the submit button (not surrounding `
    ` tag) Your currently replacing the contents of the page with the partial view that is returned
    –  Sep 17 '14 at 01:55
  • put it below the submit button and results are the same.

    @{Html.Partial("_ClientResults", Model);}
    }
    – user961346 Sep 17 '14 at 02:23

0 Answers0