TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Thamsanqa Ngcongwane
NA
184
24.9k
How to Pass data from Ajax to Controller method ?
Jun 18 2020 1:11 PM
Hi Everyone,
I have the following javascript code:
<script>
function
RequestData() {
var
Nos = $(
"#search"
).val();
var
DataIntervals = $(
"#txtDataInterval"
).val();
var
StartDates = $(
"#start_date"
).val();
var
EndDates = $(
"#end_date"
).val();
if
(Nos !=
null
&& DataIntervals !=
null
&& StartDates !=
null
&& EndDates !=
null
)
{
$.ajax({
type:
"POST"
,
async:
false
,
url:
'ExtractData/ExtractData'
,
data: {
'No'
: Nos,
'DataInterval'
: DataIntervals,
'StartDate'
: StartDates,
'EndStart'
: EndDates},
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
success:
function
(msg) {
alert(
"The Query Has Completed Successfully."
);
},
error:
function
(e) {
alert(
"Something Went Wrong Please Try Again."
+ e);
}
});
}
else
{
alert(
"Please Select All The Required Fields and Try Again."
);
}
}
</script>
I'm trying to pass to parameters to C# method but they always null.
Here is my C# method:
[HttpPost]
public
IActionResult ExtractData(
string
No,
string
DataInterval,
string
StartDate,
string
EndStart)
{
string
x = No;
return
View();
}
What is it I'm doing wrong that makes this method parameters to always be null?
Reply
Answers (
2
)
Any examples of cookie authentication in asp.net core.
Continue Adding Value from TextBox