My Index View is
@model IEnumerable<W.Models.Abc
@using (Ajax.BeginForm("getAbcListA", "Home", new AjaxOptions { UpdateTargetId = "AbcDetails" }))
{
<b>Search By:</b>@Html.RadioButton("Searchby", "Name", true, new { style = "width:20px;" }) <text>Name</text>
@Html.RadioButton("Searchby", "Id", new { style = "width:20px;" }) <text>ID</text>
@Html.TextBox("Search") <input type="submit" value="Search" class="Searchbtn"/>
}
<div id="AbcDetails" style="width: 35%; height: 130px; display:none;">
</div>
and my java script file is
$(document).ready(function () {
$.ajax({
url: '/Home/getAbcList',
contentType: 'application/html; charset=utf-8',
type: 'GET',
dataType: 'html'
})
.success(function (result) {
$('#AbcDetails').show();
$('#AbcDetails').html(result);
})
.error(function (xhr, status) {
alert('from function');
});
$(".Searchbtn").click(function () {
$("#AbcDetails").hide();
});
});
and my controller is
public ActionResult getAbcList()
{
var obj = repository.Searchlist();
return View("_getAbcList",obj);
}
and second function (called by Ajax form) is
public ActionResult getAbcListA(string a, string b)
{
var obj = repository.Searchlist(a,b);
return View("_getAbcList",obj);
}
and my partial view is
@model IEnumerable<W.Models.Abc>
@{
WebGrid grid = new WebGrid(Model,
columnNames: new[] { "FirstName", "SurName", "Date", "Address", "PostCode", "ContactNumber" }
, defaultSort: "FirstName"
, rowsPerPage: 15
, canPage: true
// canSort: true
);
}
The problem is that when the page loads first time it doesnt display the partial view and sends an error(from function) which i defined in method. Even if I render the partial view in my Index View
<div id="AbcDetails" style="width: 35%; height: 130px; display:none;">
@{Html.RenderPartial("~/Views/Home/_getAbcList.cshtml");}
</div>
then the partial view displays the data but the grid goes down the footer tag (body and footer content is being displayed as a background of grid). I want to load the data via ajax when page first loads and the when User clicks on button then the partial view should be displayed I know I have to define another div to show and current one to hide....Please help.....
@{Html.RenderAction("_getAbcList","YourController")}your index view