Hello Term,
I have 4 tables, and table one is tblCLass which contain ClassId and ClassName, and table two is tblRegistrationFeesTable
which contain RegistrationId, Fees, and ClassId and the Table 3 is tblTerm which contain TermId and TermName,
and in table 4 is tblFeesPayment which contain FeesId,Payment date Student name,TermId, RegistrationId,ClassId, FeesPaid, Wallet and and I want to select ClassName and then it will fetch Fee by RegistrationId and whenever I select ClassName I want the existig fees to show in the approved textbox.
But when I select ClassName the fees doesn't show in the approved textbox.
public ActionResult GetStudentFees(int registrationId, int classId)
{
decimal SchoolFees = objBasicShoolDBEntities.tblRegistrationFees.Single(model => model.RegistrationId == registrationId && model.ClassId == classId).Fees;
return Json(SchoolFees, JsonRequestBehavior.AllowGet);
}
function GetTermlyFees(registrationId) {
$.ajax({
async: true,
type: 'GET',
dataType: 'JSON',
contentType: 'application/json; charset=utf-8',
data: { registrationId: registrationId},
url: '/Home/GetStudentFees',
success: function (data) {
$("#txtRegistrationFees").val(parseFloat(data).toFixed(2));
},
error: function () {
alert("There is some problem to get school fees.");
}
});
}
Prasad RaveendranPosted May 8, 2024, 12:40 AM
try this approach
if its going to else part, we may need to look at the your entity relationship which you have configured
Ricepuritytest BloggerPosted May 16, 2024, 8:58 AM
Am thinking may be the reason why the fees is not coming is how am selecting the class name, from above query
Emmmanuel FIADUFEPosted May 10, 2024, 8:46 PM
Thank you team,
I change the class table and registration table to one instead of two and it is working the way I want it.
Jignesh KumarPosted May 9, 2024, 3:54 AM
Hello Emmmanuel,
As you shared SQL server table data in that snippet there is no registrationId = 11. could you please check that table you are getting values for registrationId 11;
If not then please select other which are eixists in table and test it.
Emmmanuel FIADUFEPosted May 8, 2024, 3:52 PM
Am thinking may be the reason why the fees is not coming is how am selecting the class name, from above query
Emmmanuel FIADUFEPosted May 7, 2024, 8:25 PM
Hello Kumar
even though the error is no longer showing, when I select the ClassName it doesn't fetch it associated fee, any other help would be greatly appreciated
Jignesh KumarPosted May 7, 2024, 2:57 AM
Hello Emmmanuel,
As per your last code snnipet, You are passing only registrationId from your AJAX call but in mvc controller you have two parameter
registrationId and TemlyFeesPaymentViewModel, so this one must change only the registrationId you need to pass in the controller method as well.
As per your table data registration Id is primary key so only one row will be there for one registrationId,
Emmmanuel FIADUFEPosted May 6, 2024, 10:08 PM
With the debugger in the JavaScript function, is selecting the FeeId alright but the function says localhost: says there is some problem to get school fees
Emmmanuel FIADUFEPosted May 6, 2024, 5:47 PM
Please it is still not working, any other way would be appreciated
Emmmanuel FIADUFEPosted May 6, 2024, 3:27 PM
Jobin yes classInfo has ClassId
Jobin SPosted May 6, 2024, 3:18 PM
Hi ,
if (registrationFee == null) Check this condition null criteia
I need to debug the code to see if the
classInfoobject has aClassIdproperty and check whether it's filled in correctly. I can go through the code line by line to make sure everything's as expectedEmmmanuel FIADUFEPosted May 6, 2024, 2:06 PM
Hello Kumar,
The query works perfectly when I execute in the SQL database, it fetch the first row
Jignesh KumarPosted May 6, 2024, 12:50 PM
Have you checked registrationId and classId values from the method parameter,
if you are getting the below parameter,
registrationId =3 , classId =11
Then below query will execute in the SQL server and return the first row,
execute below query and check in sql server.
Jignesh KumarPosted May 6, 2024, 3:23 AM
Hello Emmmanuel,
Are you getting error? if Yes
then you need to check this line,
in Linq the .single () extension method expects only single values for specified where clause. In the above case maybe you are not getting values or maybe more than one value for given registrationId and classId.
Jobin SPosted May 6, 2024, 12:43 AM
Hi Emmanuel,
in Ajax Function some modification