Reputation: 439
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>
the jquery for this is
$(document).ready(function () {
$("#SearchResultbtn").click(function () {
$.get('/Views/Shared/_AdminSearchResult.cshtml', function (data) {
$('#searchResult').html(data);
});
});
});
My controller method is
[HttpPost]
public ActionResult CreateAdmin(string button, Administration admin)
{
if (button == "search")
{
var result = Administration.GetAdministrationList();
if (result.Count() != 0)
return PartialView("_AdminSearchResult", result);
}
}
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.
Upvotes: 2
Views: 969
Reputation: 2550
This should read something along these lines:
$(document).ready(function (e) {
$("#SearchResultbtn").click(function (e) {
e.preventDefault();
$("#searchResult").load('@Url.Action("CreateAdmin")');
});
});
Upvotes: 1