How to get value of form filed card_number to pass to the controller?










0















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;










share|improve this question






















  • 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 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
















0















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;










share|improve this question






















  • 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 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














0












0








0








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;










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 19:08









anatp_123anatp_123

3981316




3981316












  • 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 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


















  • 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 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

















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













1 Answer
1






active

oldest

votes


















0














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






share|improve this answer
























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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






    share|improve this answer





























      0














      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






      share|improve this answer



























        0












        0








        0







        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






        share|improve this answer















        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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 15 '18 at 20:00

























        answered Nov 15 '18 at 19:52









        ShyjuShyju

        147k87335445




        147k87335445





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands