本文介绍了在新页面上呈现PartialView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在名为CreateAdmin的父视图中,我有一些HTML控件,按钮和用于局部视图的div占位符
In my Parent view called CreateAdmin I have some Html Controls, button and a div place holder for partial view
@using (Html.BeginForm())
{
<p style="padding-left: 920px;">
<button name="button" value="search" id="SearchResultbtn">
Search</button>
</p>
<div class="editor-field" id="searchResult">
//place holder for the partial view
</div>
}
点击搜索"按钮时,局部视图应在此内部动态呈现
when clicked on button "Search" the partial view should be rendered dynamically inside this
<div id="searchResult"><div>
为此的jquery是
$(document).ready(function () {
$("#SearchResultbtn").click(function () {
$.get('/Views/Shared/_AdminSearchResult.cshtml', function (data) {
$('#searchResult').html(data);
});
});
});
我的控制器方法是
[HttpPost]
public ActionResult CreateAdmin(string button, Administration admin)
{
if (button == "search")
{
var result = Administration.GetAdministrationList();
if (result.Count() != 0)
return PartialView("_AdminSearchResult", result);
}
}
我在共享文件夹中的部分视图是_AdminSearchResult.cshtml.
I have my partial view in shared folder name is _AdminSearchResult.cshtml.
问题在于部分视图正在新页面中呈现,而不是在新页面中呈现.有人可以指出我要去哪里吗?
The problem is that the partial view is being render in a new page instead of the place where it is suppose to. Can someone please point out where am i going worng.
推荐答案
这应遵循以下内容:
$(document).ready(function (e) {
$("#SearchResultbtn").click(function (e) {
e.preventDefault();
$("#searchResult").load('@Url.Action("CreateAdmin")');
});
});
这篇关于在新页面上呈现PartialView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!