This question is locked. New answers and comments are not allowed.
Hi..
Editing paging .sorting is working fine but filtering is not working.
please review the below code..whats problem here
asox page code
@(Html.Telerik().Grid<TelerikMvcApplication1.Models.tb_TestMvc>()
.BindTo((List<TelerikMvcApplication1.Models.tb_TestMvc>)ViewData["tb_TestMvc"])
.Name("Grid")
.DataKeys(keys =>
{
keys.Add(p => p.Id);
})
.DataBinding(dataBinding => dataBinding.Server()
.Update("UpdateTest", "HOME")
.Insert("InsertTest", "HOME")
.Delete("DeleteTest", "HOME")
)
.Columns(columns =>
{
columns.Bound(p => p.Id).Width(210);
columns.Bound(p => p.ContactTitle).Width(130).Format("{0:c}");
columns.Bound(p => p.ContactName).Width(130).Format("{0:N}");
columns.Bound(p => p.Country).Width(130).Format("{0:d}");
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
});
})
.ToolBar(t =>
{
t.Insert();
})
.Sortable()
.Pageable(paging => paging.PageSize(5))
.Filterable()
)
On controller code
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
var tme = new db_TestEntities();
ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();
return View();
}
public ActionResult About()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateTest(int Id)
{
var tst = new test
{
Id = Id,
};
if (TryUpdateModel(tst))
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = "Update tb_TestMvc set Contacttitle=@Contacttitle,ContactName=@ContactName,Country=@country where Id=@Id";
cmd1.Connection = con;
cmd1.Parameters.AddWithValue("@Id", Id);
cmd1.Parameters.AddWithValue("@Contacttitle", tst.Contacttitle);
cmd1.Parameters.AddWithValue("@ContactName", tst.ContactName) ;
cmd1.Parameters.AddWithValue("@Country", tst.Country);
cmd1.ExecuteNonQuery();
con.Close();
}
var tme = new db_TestEntities();
ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();
return RedirectToAction("Index", "Home");
// return View("Index");
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult InsertTest(int Id, string Contacttitle)
{
var tst = new test
{
Id = Id,
};
if (TryUpdateModel(tst))
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = "Insert into tb_TestMvc (Id,Contacttitle,ContactName,Country) values (@Id,@Contacttitle,@ContactName,@Country)";
cmd1.Connection = con;
cmd1.Parameters.AddWithValue("@Id", Id);
cmd1.Parameters.AddWithValue("@Contacttitle", Contacttitle);
cmd1.Parameters.AddWithValue("@ContactName", tst.ContactName) ;
cmd1.Parameters.AddWithValue("@Country", tst.Country);
cmd1.ExecuteNonQuery();
con.Close();
}
var tme = new db_TestEntities();
ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();
return RedirectToAction("Index", "Home");
// return View("Index");
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DeleteTest(int Id, string Contacttitle)
{
var tst = new test
{
Id = Id,
};
if (TryUpdateModel(tst))
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = "Delete from tb_TestMvc where Id=@Id";
cmd1.Connection = con;
cmd1.Parameters.AddWithValue("@Id", Id);
cmd1.ExecuteNonQuery();
con.Close();
}
var tme = new db_TestEntities();
ViewData["tb_TestMvc"] = tme.tb_TestMvc.ToList();
return RedirectToAction("Index", "Home");
// return View("Index");
}
}