我想根据_partialA中的Name
值加载_partialB。我的方案中Name
是按钮。
我收到以下错误:
未捕获错误:无法在同一帧中加载XRegExp两次
控制器
public ActionResult ABC(string name="")
{
SDetails sDetails=new SDetails();
var model = new ClsA();
if(name=="")
{
name = sDetails.Rst().FirstOrDefault().Name;
model.firsts = sDetails.Rst();
model.seconds = sDetails.Rs(name);
}
else
{
model.firsts = sDetails.Rst();
model.seconds = sDetails.Rs(name);
}
return View(model);
}
查看
@model Aplication.Models.ABC.ClsA
<div id=myA>
@{ Html.RenderPartial("_PartialA", Model.firsts); }
</div>
<div id=myB>
@{ Html.RenderPartial("_PartialB", Model.seconds);}
</div>
_PartialA
@model IEnumerable<Aplication.Models.ABC.first>
<table>
<tr>
<th>@Html.DisplayNameFor(m => m.Name)</th>
<th>@Html.DisplayNameFor(m => m.Address)</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<button class="link" type="button" data-
name="@item.name">
@Html.DisplayFor(modelItem => item.Name)
</button>
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
</tr>
}
</table>
脚本
$('#myA').on('click', '.link', function () {
debugger;
var name= $(this).data("name");
var url = '@Url.Action("ABC", "ABC")?name=' + name;
$('#myB').load(url);
});
答案 0 :(得分:1)
您需要一个仅返回_PartialB.cshtml
public PartialViewResult PartialB(string name)
{
List<first> model = sDetails.Rs(name);
return PartialView("_PartialB", model);
}
并将您的脚本修改为
$('#myA').on('click', '.link', function () {
var name= $(this).data("name");
var url = '@Url.Action("PartialB")'; // assumes its in the same controller
$('#myB').load(url, { name: name });
});