1nn0c3ntv5
Fanatic
Gumawa ako ng IDataProvider interface, DataProviderInterface, DataGetController, at may view ako na Accounts.cshtml
IDataProvider Syntax:
public interface IDataProvider
{
List<Volunteer> GetVolunteer();
}
DataProvider Syntax:
public class DataProvider : DataAccess, IDataProvider
{
public List<Volunteer> GetVolunteer()
{
var result = new List<Volunteer>();
using (IDbConnection con = new SqlConnection(constring))
{
con.Open();
result = con.Query<Volunteer>(
StoredProcedureEnum.V_Volunteer.ToString(), commandType: CommandType.StoredProcedure).ToList();
}
return result;
}
}
DataGetController Syntax:
public class DataGetController : Controller
{
IDataProvider _IDataProvider;
public DataGetController()
{
_IDataProvider = new DataProvider();
}
public JsonResult GetVolunteer()
{
var data = _IDataProvider.GetVolunteer();
return Json(data, JsonRequestBehavior.AllowGet);
}
}
Ito yung problema ayaw niya mag display sa view:
Accounts.cshtml
<script>
$(document).ready(function () {
LoadVolunteer();
LoadMyTrial();
});
function LoadMyTrial() {
//debugger;
var temp;
$.ajax({
type: "GET",
"url": "/DataGet/GetVolunteer",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (result) {
//alert(JSON.stringify(result));
$.each(response, function () {
temp.append('VolunteerID');
});
},
error: function (response) {
// debugger;
alert('error');
}
});
alert(temp);
}
</script>
nag didisplay naman siya pag gumamit ako ng
alert(JSON.stringify(result));
pero pano kung gusto ko lang makuha ay yung VolunteerID nila?
IDataProvider Syntax:
public interface IDataProvider
{
List<Volunteer> GetVolunteer();
}
DataProvider Syntax:
public class DataProvider : DataAccess, IDataProvider
{
public List<Volunteer> GetVolunteer()
{
var result = new List<Volunteer>();
using (IDbConnection con = new SqlConnection(constring))
{
con.Open();
result = con.Query<Volunteer>(
StoredProcedureEnum.V_Volunteer.ToString(), commandType: CommandType.StoredProcedure).ToList();
}
return result;
}
}
DataGetController Syntax:
public class DataGetController : Controller
{
IDataProvider _IDataProvider;
public DataGetController()
{
_IDataProvider = new DataProvider();
}
public JsonResult GetVolunteer()
{
var data = _IDataProvider.GetVolunteer();
return Json(data, JsonRequestBehavior.AllowGet);
}
}
Ito yung problema ayaw niya mag display sa view:
Accounts.cshtml
<script>
$(document).ready(function () {
LoadVolunteer();
LoadMyTrial();
});
function LoadMyTrial() {
//debugger;
var temp;
$.ajax({
type: "GET",
"url": "/DataGet/GetVolunteer",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (result) {
//alert(JSON.stringify(result));
$.each(response, function () {
temp.append('VolunteerID');
});
},
error: function (response) {
// debugger;
alert('error');
}
});
alert(temp);
}
</script>
nag didisplay naman siya pag gumamit ako ng
alert(JSON.stringify(result));
pero pano kung gusto ko lang makuha ay yung VolunteerID nila?