there are two method
one is Action Result StudyMaterial, second is JsonResult getchapter()
both method worh on page load
can i bind this two method in one method
can i return view and json data both
like
return view("index", mylist,JsonRequestBehavior.AllowGet)
public ActionResult StudyMaterial()
{
return View();
}
public JsonResult getchapter()
{
string courseid = Session["courseid"].ToString();
string subjectid = Session["courseid"].ToString();
List<SelectListItem> myList = new List<SelectListItem>();
DataTable dt = new DataTable();
try
{
string query = "usp_tbl_topic";
using (SqlConnection con = Connection.getConnection())
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.Clear();
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@courseid", SqlDbType.NVarChar).Value = courseid;
cmd.Parameters.AddWithValue("@subjectid", SqlDbType.NVarChar).Value = subjectid;
cmd.Parameters.AddWithValue("@flag", SqlDbType.NVarChar).Value = "Z";
SqlDataAdapter sdr = new SqlDataAdapter(cmd);
sdr.Fill(dt);
cmd.Connection = con;
con.Close();
}
}
foreach (DataRow dtRow in dt.Rows)
{
//foreach(DataColumn dc in dtRow)
myList.Add(new SelectListItem
{
Text = dtRow["chaptername"].ToString(),
Value = dtRow["chapterid"].ToString(),
});
}
}
catch(Exception ex)
{
}
return Json(myList, JsonRequestBehavior.AllowGet);
}