Hi All,
I am using webgrid in MVC it working fine, its edit delete and paging action working fine.But I have some extra requirement in page load we have 2 dropdown so on the basis of dropdown we have to bind my webgrid.
So implement this functionality i am creating webgrid from controller so everything is fine but paging and Edit delete is not showing.How we achieve this....
i have done webgrid for 1 st time load in View Section like -
@grid.GetHtml(htmlAttributes: new {id = "Gridv"},
fillEmptyRows: true,
alternatingRowStyle: "alternate-row",
headerStyle: "grid-header",
footerStyle: "grid-footer",
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: new [] {
grid.Column("Ordinal"),
grid.Column("CourseName",header:"Course Name"),
grid.Column("CourseDisplatTitle",header:"Description"),
grid.Column("LanguageName",header:"Language"),
grid.Column("ThemeName",header:"Theme"),
grid.Column("LinkedCourses"),
grid.Column("Enabled",header:"Active"),
//grid.Column("FriendlyId", style:"hidecol",header:""),
grid.Column(null,null, format: @<input type="hidden" name="IDHidden" value="@item.FriendlyId"/>),
grid.Column("",
header: "Actions",
format: @<text>
@Html.ActionLink("Edit", "EditCourse", new { id=item.CourseId} )
|
@Html.ActionLink("Delete", "DeleteCourse", new { id=item.CourseId} , new { onclick="return confirm('Are you sure?');"})
</text>
)
})
but in 2 nd time when we do filter we are doing in controller like-
[HttpGet]
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult CustomDataAll()
{
var tms = BusinessLayer.ThemeManager.GetThemes().ToList();
var crs = BusinessLayer.CourseManager.GetCourses().ToList();
var por = BusinessLayer.PortalManager.GetPortals();
var mod = BusinessLayer.ModuleManager.GetModules().ToList();
var result = from c in crs
join th in tms on c.ThemeId equals th.Id
join pr in por on th.PortalId equals pr.Id
join m in mod on c.Id equals m.CourseId into modules
select new
{
CourseId = c.Id,
CourseName = c.Name,
ThemeId = th.Id,
ThemeName = th.Name,
LanguageID = pr.Id,
LanguageName = pr.Name,
FriendlyId = c.FriendlyId,
Ordinal = c.Ordinal,
CourseDisplatTitle = c.CourseDisplayTitle,
Enabled = c.Enabled,
LinkedCourses = modules.Count()
};
var grid = new System.Web.Helpers.WebGrid(result);
var htmlString = grid.GetHtml();
return Json(new
{
Data = htmlString.ToHtmlString()
}
, JsonRequestBehavior.AllowGet);
}
I am not able to implement edit delete and paging functionality in this 2 section...which ajax funtion is using in 2nd time is like this-
<script type="text/javascript">
$(function () {
$('#modTheme_DataValueField').change(function () {
var selectedValue = $(this).val();
if (selectedValue != "") {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: '@Url.Action("CustomData", "ContentUpload")',
data: { "themeid": selectedValue },
dataType: "json",
beforeSend: function () {
},
success: function (data) {
var items = "";
var i = 0;
$('#Gridv').html(data.Data);
},
error: function (result) {
}
});
}
else {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: '@Url.Action("CustomDataAll", "ContentUpload")',
data: { },
dataType: "json",
beforeSend: function () {
},
success: function (data) {
var items = "";
var i = 0;
$('#Gridv').html(data.Data);
},
error: function (result) {
alert('Service call failed: ' + result.status + ' Type :' + result.statusText);
}
});
}
});
});
</script>