我在另一个局部视图中有一个局部视图,当第一次运行应用程序按预期加载时,但是当你单击重新加载视图以将模型推入其中时,它会呈现为它自己完全独立的视图,就好像它一样不是偏袒的。
我在Ajax表单中调用它(在Action链接上单击,_GetSearchModal方法):
<div id="modelSearch">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-search"></i> Search by Model / Manufacturer
</h3>
</div>
<div class="panel-body">
@using (Ajax.BeginForm("_GetSearch", "Home", new AjaxOptions() {UpdateTargetId = "modelSearch"}))
{
@Html.AntiForgeryToken()
<div class="input-group">
@Html.TextBox("search", null, new {id = "name", @class = "form-control", placeholder = "Please enter a manufacturer or model"})
<span class="input-group-btn">
<button id="search" class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>
</span>
</div>
if (Model != null)
{
<div id="searchResults" class="fade-in two">
@foreach (var s in Model)
{
<div class="result">
@switch (s.ResultType)
{
case "Man":
<a href="#">@s.Manufacturer</a>
break;
case "Mod":
@Html.ActionLink(s.Manufacturer + Html.Raw(s.Model), "_GetSearchModal", "Home", new {id = s.MachineId}, new {toggle = "modal", data_target = "#MachineModal"})
<img src="~/Images/General/Tier/@(s.TierId).png" alt="Tier @s.TierId"/>
break;
}
</div>
}
</div>
}
}
</div>
</div>
</div>
<!-- Product Modal -->
<div class="modal fade" id="MachineModal" tabindex="-1" role="dialog" aria-labelledby="MachineModalLabel">
@Html.Partial("_SearchModal", new MachineModal())
</div>
视图本身应加载不同的视图模型(MachineModal):
@model SpecCheck.Portals.Web.UI.ViewModels.MachineModal
@if (Model != null)
{
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="MachineModalLabel">@Model.Manufacturer @Model.Model</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<img src="~/Images/@Model.Manufacturer/logo.png" alt="@Model.Manufacturer" /><br />
<a href="#" type="button" class="btn button">Wiki</a>
</div>
<div class="col-md-6">
@Model.Catagory1 | @Model.Category2<br /><br />
<span class="modal-em">Region: </span> @Model.Region<br />
<span class="modal-em">Status: </span>@Model.Status<br />
<span class="modal-em">Spec Date: </span>@Model.SpecDate
</div>
</div>
</div>
<div class="modal-footer">
<a href="#" type="button" class="btn button">View</a>
<a href="#" type="button" class="btn button">Quick Compare</a>
<a href="#" type="button" class="btn button">Compare</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
}
在“家庭控制器”中执行此操作的操作是:
public ActionResult _GetSearchModal(string machineId)
{
using (var db = new SpecCheckDbContext())
{
MachineModal machine = new MachineModal();
var searchHelper = new SearchHelper(db);
//Get Machine Details
var dbResults = searchHelper.SearchModal(Convert.ToInt32(machineId));
machine.Model = dbResults.Model;
machine.Catagory1 = dbResults.Catagory1;
machine.Category2 = dbResults.Category2;
machine.Manufacturer = dbResults.Manufacturer;
machine.Region = dbResults.Region;
machine.SpecDate = dbResults.SpecDate;
machine.Status = dbResults.Status;
machine.MachineId = dbResults.MachineId;
machine.ManufacturerId = dbResults.ManufacturerId;
var model = machine;
return PartialView("_SearchModal", model);
}
}
我检查的第一件事是脚本,当布局页面加载时它们全部到位,因此它不是脚本问题。不知道要改变什么甚至尝试在这一点,所以欢迎任何建议。
答案 0 :(得分:3)
以ajax形式:
_GetSearch => _GetSearchModal(name of the action)
尝试将machine
返回到局部视图?也许在View层次结构中看到,是否有第二个_SearchModal
部分视图会被返回?