How to get value of form filed card_number to pass to the controller?
How would I get the value of card_number to pass to the controller?
Every time I submit the form I get NULL in the form variable
View:
@Html.EditorFor(model => model.card_number, new htmlAttributes = new @id = "card_number" )
<script>
var frm = $('#formFilter');
function OnFormSubmit()
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: function (frm)
frm.card_number = $('#card_number').val();
,
success: function (data)
$("#dataResult").html(data);
$('#dataTable').DataTable(
"dom": 'lifrtp'
);
);
</script>
controller:
private List<testtest> GetListChanges(Report changeControl)
...logic here....
return returnListhere;
asp.net-mvc datatables
add a comment |
How would I get the value of card_number to pass to the controller?
Every time I submit the form I get NULL in the form variable
View:
@Html.EditorFor(model => model.card_number, new htmlAttributes = new @id = "card_number" )
<script>
var frm = $('#formFilter');
function OnFormSubmit()
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: function (frm)
frm.card_number = $('#card_number').val();
,
success: function (data)
$("#dataResult").html(data);
$('#dataTable').DataTable(
"dom": 'lifrtp'
);
);
</script>
controller:
private List<testtest> GetListChanges(Report changeControl)
...logic here....
return returnListhere;
asp.net-mvc datatables
serialize the form and send that as ajaxdata?
– Shyju
Nov 15 '18 at 19:14
@Shyju I know I can do this data: frm.serialize(), but I would like to do this another way.
– anatp_123
Nov 15 '18 at 19:16
How does yourReportclass looks like ? Are you gettingnullnow ?
– Shyju
Nov 15 '18 at 19:33
@Shyju no, if i use the "data: frm.serialize()," I am able to get the values
– anatp_123
Nov 15 '18 at 19:34
add a comment |
How would I get the value of card_number to pass to the controller?
Every time I submit the form I get NULL in the form variable
View:
@Html.EditorFor(model => model.card_number, new htmlAttributes = new @id = "card_number" )
<script>
var frm = $('#formFilter');
function OnFormSubmit()
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: function (frm)
frm.card_number = $('#card_number').val();
,
success: function (data)
$("#dataResult").html(data);
$('#dataTable').DataTable(
"dom": 'lifrtp'
);
);
</script>
controller:
private List<testtest> GetListChanges(Report changeControl)
...logic here....
return returnListhere;
asp.net-mvc datatables
How would I get the value of card_number to pass to the controller?
Every time I submit the form I get NULL in the form variable
View:
@Html.EditorFor(model => model.card_number, new htmlAttributes = new @id = "card_number" )
<script>
var frm = $('#formFilter');
function OnFormSubmit()
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: function (frm)
frm.card_number = $('#card_number').val();
,
success: function (data)
$("#dataResult").html(data);
$('#dataTable').DataTable(
"dom": 'lifrtp'
);
);
</script>
controller:
private List<testtest> GetListChanges(Report changeControl)
...logic here....
return returnListhere;
asp.net-mvc datatables
asp.net-mvc datatables
asked Nov 15 '18 at 19:08
anatp_123anatp_123
3981316
3981316
serialize the form and send that as ajaxdata?
– Shyju
Nov 15 '18 at 19:14
@Shyju I know I can do this data: frm.serialize(), but I would like to do this another way.
– anatp_123
Nov 15 '18 at 19:16
How does yourReportclass looks like ? Are you gettingnullnow ?
– Shyju
Nov 15 '18 at 19:33
@Shyju no, if i use the "data: frm.serialize()," I am able to get the values
– anatp_123
Nov 15 '18 at 19:34
add a comment |
serialize the form and send that as ajaxdata?
– Shyju
Nov 15 '18 at 19:14
@Shyju I know I can do this data: frm.serialize(), but I would like to do this another way.
– anatp_123
Nov 15 '18 at 19:16
How does yourReportclass looks like ? Are you gettingnullnow ?
– Shyju
Nov 15 '18 at 19:33
@Shyju no, if i use the "data: frm.serialize()," I am able to get the values
– anatp_123
Nov 15 '18 at 19:34
serialize the form and send that as ajax
data ?– Shyju
Nov 15 '18 at 19:14
serialize the form and send that as ajax
data ?– Shyju
Nov 15 '18 at 19:14
@Shyju I know I can do this data: frm.serialize(), but I would like to do this another way.
– anatp_123
Nov 15 '18 at 19:16
@Shyju I know I can do this data: frm.serialize(), but I would like to do this another way.
– anatp_123
Nov 15 '18 at 19:16
How does your
Report class looks like ? Are you getting null now ?– Shyju
Nov 15 '18 at 19:33
How does your
Report class looks like ? Are you getting null now ?– Shyju
Nov 15 '18 at 19:33
@Shyju no, if i use the "data: frm.serialize()," I am able to get the values
– anatp_123
Nov 15 '18 at 19:34
@Shyju no, if i use the "data: frm.serialize()," I am able to get the values
– anatp_123
Nov 15 '18 at 19:34
add a comment |
1 Answer
1
active
oldest
votes
The data property of the $.ajax method options should be an object or string which represents your data. With your current code you are setting a function to that.
var d =
card_number: "1234",
someOtherPropertyNameOfReport: "Hello"
;
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: JSON.stringify(d),
contentType:"application/json",
success: function (data)
console.log(data);
);
Now jquery will send the request with Content-Type request header value set to application/json and request data (the stringified version of your JavaScript object) in the request body and model binder will be able to properly read and map it to your view model, assuming the structure of the view model matches with your JavaScript object structure.
As suggested in the comment, try to use serialize() method. It is simply and you do not need to manually build the object.
Also your controller action method should be public
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326388%2fhow-to-get-value-of-form-filed-card-number-to-pass-to-the-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The data property of the $.ajax method options should be an object or string which represents your data. With your current code you are setting a function to that.
var d =
card_number: "1234",
someOtherPropertyNameOfReport: "Hello"
;
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: JSON.stringify(d),
contentType:"application/json",
success: function (data)
console.log(data);
);
Now jquery will send the request with Content-Type request header value set to application/json and request data (the stringified version of your JavaScript object) in the request body and model binder will be able to properly read and map it to your view model, assuming the structure of the view model matches with your JavaScript object structure.
As suggested in the comment, try to use serialize() method. It is simply and you do not need to manually build the object.
Also your controller action method should be public
add a comment |
The data property of the $.ajax method options should be an object or string which represents your data. With your current code you are setting a function to that.
var d =
card_number: "1234",
someOtherPropertyNameOfReport: "Hello"
;
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: JSON.stringify(d),
contentType:"application/json",
success: function (data)
console.log(data);
);
Now jquery will send the request with Content-Type request header value set to application/json and request data (the stringified version of your JavaScript object) in the request body and model binder will be able to properly read and map it to your view model, assuming the structure of the view model matches with your JavaScript object structure.
As suggested in the comment, try to use serialize() method. It is simply and you do not need to manually build the object.
Also your controller action method should be public
add a comment |
The data property of the $.ajax method options should be an object or string which represents your data. With your current code you are setting a function to that.
var d =
card_number: "1234",
someOtherPropertyNameOfReport: "Hello"
;
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: JSON.stringify(d),
contentType:"application/json",
success: function (data)
console.log(data);
);
Now jquery will send the request with Content-Type request header value set to application/json and request data (the stringified version of your JavaScript object) in the request body and model binder will be able to properly read and map it to your view model, assuming the structure of the view model matches with your JavaScript object structure.
As suggested in the comment, try to use serialize() method. It is simply and you do not need to manually build the object.
Also your controller action method should be public
The data property of the $.ajax method options should be an object or string which represents your data. With your current code you are setting a function to that.
var d =
card_number: "1234",
someOtherPropertyNameOfReport: "Hello"
;
$.ajax(
type: frm.attr('method'),
url: frm.attr('action'),
data: JSON.stringify(d),
contentType:"application/json",
success: function (data)
console.log(data);
);
Now jquery will send the request with Content-Type request header value set to application/json and request data (the stringified version of your JavaScript object) in the request body and model binder will be able to properly read and map it to your view model, assuming the structure of the view model matches with your JavaScript object structure.
As suggested in the comment, try to use serialize() method. It is simply and you do not need to manually build the object.
Also your controller action method should be public
edited Nov 15 '18 at 20:00
answered Nov 15 '18 at 19:52
ShyjuShyju
147k87335445
147k87335445
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326388%2fhow-to-get-value-of-form-filed-card-number-to-pass-to-the-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
serialize the form and send that as ajax
data?– Shyju
Nov 15 '18 at 19:14
@Shyju I know I can do this data: frm.serialize(), but I would like to do this another way.
– anatp_123
Nov 15 '18 at 19:16
How does your
Reportclass looks like ? Are you gettingnullnow ?– Shyju
Nov 15 '18 at 19:33
@Shyju no, if i use the "data: frm.serialize()," I am able to get the values
– anatp_123
Nov 15 '18 at 19:34