i do not want create model class for data i directly send data to webapi controller, but not work mens in api controller not hit.
[AcceptVerbs("GET", "POST")]
public HttpResponseMessage Getcourses(string pid, string pname)
{
DataTable dt = new DataTable();
string query = "[usp_tbl_parentcourse]";
using (SqlConnection con = Connection.getConnection())
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@pcourseid", SqlDbType.Int).Value = pid;
cmd.Parameters.AddWithValue("@pcoursename", SqlDbType.NVarChar).Value = pname;
cmd.Parameters.AddWithValue("@widget_image", SqlDbType.NVarChar).Value = "";
cmd.Parameters.AddWithValue("@icon_image", SqlDbType.NVarChar).Value = "";
cmd.Parameters.AddWithValue("@addedon", SqlDbType.DateTime).Value = System.DateTime.Now;
cmd.Parameters.AddWithValue("@addedby", SqlDbType.NVarChar).Value = "Admin";
cmd.Parameters.AddWithValue("@updatedon", SqlDbType.DateTime).Value = System.DateTime.Now;
cmd.Parameters.AddWithValue("@updatedby", SqlDbType.NVarChar).Value = "Admin";
cmd.Parameters.AddWithValue("@deletedon", SqlDbType.DateTime).Value = System.DateTime.Now;
cmd.Parameters.AddWithValue("@deletedby", SqlDbType.NVarChar).Value = "Admin";
cmd.Parameters.AddWithValue("@sts", SqlDbType.NVarChar).Value = "a";
cmd.Parameters.AddWithValue("@flag", SqlDbType.NVarChar).Value = "SA";
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sdr = new SqlDataAdapter(cmd);
sdr.Fill(dt);
cmd.Connection = con;
con.Close();
}
}
if (dt.Rows.Count <= 0)
{
dt.Clear();
dt.Columns.Add("error", typeof(System.String));
dt.Columns.Add("msg", typeof(System.String));
DataRow _ravi = dt.NewRow();
_ravi["error"] = "false";
_ravi["msg"] = "Not Found";
dt.Rows.Add(_ravi);
dt.AcceptChanges();
}
else
{
dt.Columns.Add("error", typeof(System.String));
dt.Columns.Add("msg", typeof(System.String));
foreach (DataRow row in dt.Rows)
{
row["error"] = "True";
row["msg"] = "Found";
}
dt.AcceptChanges();
dt.Columns.Remove("addedon");
dt.Columns.Remove("addedby");
dt.Columns.Remove("updatedon");
dt.Columns.Remove("updatedby");
dt.Columns.Remove("deletedon");
dt.Columns.Remove("deletedby");
dt.Columns.Remove("sts");
dt.Columns.Remove("icon_image");
dt.Columns.Remove("widget_image");
dt.Columns["icon_image1"].ColumnName = "image";
dt.AcceptChanges();
}
var jresp = JsonConvert.SerializeObject(dt, Formatting.Indented);
var r = Request.CreateResponse(HttpStatusCode.OK, "Success");
r.Content = new StringContent(jresp, Encoding.UTF8, "application/json");
return r;
}
$.ajax({
type: "POST",
url: "/api/jyotish/adminlogin",
data: JSON.stringify({ 'subcatid': subcatid}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});