美好的一天。我怎樣才能刷新模態表數據?好吧,我有這個文本框,當用戶點擊顯示模式彈出窗口。彈出窗口內部是表格和搜索的局部視圖。當用戶搜索時,不是重新加載模態中的值,而是將我重定向到局部視圖本身。我看過很多像這樣的例子 - https://forums.asp.net/t/2098629.aspx?Advance+search+in+a+MVC+Popup+Window+ - 但仍然無法通過它。它基本上是一個模態彈出窗口,但包含一個部分視圖,一旦搜索被點擊,只需重新載入表格,不再需要。在此先感謝MVC使用實體框架的模態刷新表數據
局部查看代碼:
public ActionResult ShowTaxPayer(int? page, string searchString)
{
var user = (from u in db2.Payers
select new Taxpayer
{
ID = u.objid,
Firstname = u.firstname,
Lastname = u.lastname,
Middlename = u.middlename,
Address = u.primaryaddress
});
if (string.IsNullOrEmpty(searchString))
{
return View(user.ToList().ToPagedList(page ?? 1, 10));
}
else
{
return View(user.Where(s => s.Firstname.Contains(searchString)).ToList().ToPagedList(page ?? 1, 10));
}
}
剃刀:
@using (Html.BeginForm("Index", "Wizard", FormMethod.Post))
{
@Html.ValidationSummary(true)
<fieldset>
<div class="wizard-step">
@Html.Label("Taxpayer Name")
@Html.TextBoxFor(m => m.taxpayername, new { data_toggle = "modal", data_target = "#myModal", data_backdrop = "static", data_keyboard = "false" })
@Html.ValidationMessageFor(m => m.taxpayername)
</div>
<div class="wizard-step">
@Html.Label("Taxpayer Address")
@Html.EditorFor(m => m.taxpayeraddress)
@Html.ValidationMessageFor(m => m.taxpayeraddress)
</div>
<div class="wizard-step">
@Html.Label("Trade Name")
@Html.EditorFor(m => m.tradename)
@Html.ValidationMessageFor(m => m.tradename)
</div>
<div class="wizard-step confirm">
</div>
<p>
<input type="button" id="back-step" name="back-step" value="<-- Back" />
<input type="button" id="next-step" name="next-step" value="Next -->" />
</p>
</fieldset>
}
模態:
<div class="modal fade" id="myModal" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<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="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
@{Html.RenderAction("ShowTaxPayer", "Wizard");}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
我只是需要從我的模型加載模態數據而不是將我重定向到實際視圖。提前致謝。
請張貼javascript函數調用模型。 –
我沒有使用任何JavaScript sr。 –
實際上,您在加載頁面時加載數據。但是你想刷新表格。所以,你需要使用JavaScript。 –