所以我使用ajax.beginform来加载数据,由于某种原因,结果被加载到新页面中。我在线阅读的一切都让我相信它,因为我不包括正确的脚本,但我正在努力弄清楚我做错了什么。我甚至尝试将脚本标记添加到每个视图的顶部,结果是相同的。
这是我的_Layout.cshtml
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @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)
控制器
public ActionResult CheckCust(ClientCheckModels clientCheck)
{
CustomerInfo custInfo = new CustomerInfo(clientCheck.CustomerId);
DataModel dataModel = custInfo.GetClientData();
return PartialView("_ClientResults",dataModel);
}
主要观点
<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>
部分视图
@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>