Developers work on major issues and get them resolve for availing proper functioning application. In this post, asp.net web development team will explain the way to resolve issue related to not calling controller method. The experts will use AJAX JSON call from view page.
Today, I will explain how to resolve problem related to not calling controller method using AJAX JSON call from view page.
I see that many of users facing the issue that he or she cannot get client call of controller method when using AJAX in view page.
Two most common issues as below.
So, now we will get detail information about these problems and then I will give the solution to resolve issues.
This issue will rise when you want to pass model call values to controller method, or there is a difference between AJAX call type and controller method type that is PSOT and GET.So, for that you have to be sure that the type of AJAX call and Controller method are same.
Some times it will not work when you initialize a button with “button” type and not with “submit” type. When you set type of button to “Submit” on page, then you have to set calling method on “using” statement with HttpMethod type as below.
This is one type of AJAX call.
You can see that I am calling RegisterCustomer method with GET type of HttpMethod and my button type is “submit”. It will surely call a controller method and you will get all html control values in parameters and also you will get model class values to class parameter of method.
Second type of AJAX call is java-script call.
Here is the model class
Here you can see that I passed “dataToSend” is object type data that is define as below. Properties for these object are same as model class.
These both methods will work and call controller method.
This issue will occurs when you are trying to call HTTPGET type of control method using button type of input html control. You have to be sure when you are calling HTTPGET controller method, you have input type button control with type=submit.
Replace above line with this.
The above example is same for this issue also.
Some times when you don’t define contentType to $.ajax call, it will not call any type of controller method, so you have to be sure when you are passing JSON type object data to controller you have to define contentType as below.
Now finally, following is the order of properties for AJAX call in view or any java-script call with example.
And controller method is like this.
Please note that the coding shared by asp.net web development team is for reference purpose only. If you have any doubt or want to ask anything related to the issue, make comments below.
For further information, mail us at firstname.lastname@example.org