Model Binding failed - passing null value into action









up vote
0
down vote

favorite












With this code I am failing to pass PlayerViewModel with model binding to my action method



 @foreach (var player in Model)
{
<tr>
<td><img class="mini-avatar" src="@player.AvatarURL" /></td>
<td>@player.Username</td>
<td>@player.XP</td>
<td><button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Battle!</button></td>

<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">

<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Commencing Battle</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to fight ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
</div>
</div>

</div>
</div>
</tr>


Down bellow you can see this code snippet :



<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
</div>


The problem is that if I have, for example, 10 players, the foreach will loop 10 times, take each player and bind it into asp-route-data="@player" with it's 3 properties, and after 10 times it will go to my page where when I choose battle and the modal dialogue opens , I choose Confirm and it should send me here asp-controller="Game" asp-action="Battle"
Well, so it does, but the value passed is null. And workaround anyone? I will be very thankful! I am using HttpGet as an attribute to this Action. Is this the problem?










share|improve this question

























    up vote
    0
    down vote

    favorite












    With this code I am failing to pass PlayerViewModel with model binding to my action method



     @foreach (var player in Model)
    {
    <tr>
    <td><img class="mini-avatar" src="@player.AvatarURL" /></td>
    <td>@player.Username</td>
    <td>@player.XP</td>
    <td><button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Battle!</button></td>

    <div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">

    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Commencing Battle</h4>
    </div>
    <div class="modal-body">
    <p>Are you sure you want to fight ?</p>
    </div>
    <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
    <a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
    </div>
    </div>

    </div>
    </div>
    </tr>


    Down bellow you can see this code snippet :



    <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
    <a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
    </div>


    The problem is that if I have, for example, 10 players, the foreach will loop 10 times, take each player and bind it into asp-route-data="@player" with it's 3 properties, and after 10 times it will go to my page where when I choose battle and the modal dialogue opens , I choose Confirm and it should send me here asp-controller="Game" asp-action="Battle"
    Well, so it does, but the value passed is null. And workaround anyone? I will be very thankful! I am using HttpGet as an attribute to this Action. Is this the problem?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      With this code I am failing to pass PlayerViewModel with model binding to my action method



       @foreach (var player in Model)
      {
      <tr>
      <td><img class="mini-avatar" src="@player.AvatarURL" /></td>
      <td>@player.Username</td>
      <td>@player.XP</td>
      <td><button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Battle!</button></td>

      <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog">

      <div class="modal-content">
      <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title">Commencing Battle</h4>
      </div>
      <div class="modal-body">
      <p>Are you sure you want to fight ?</p>
      </div>
      <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      <a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
      </div>
      </div>

      </div>
      </div>
      </tr>


      Down bellow you can see this code snippet :



      <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      <a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
      </div>


      The problem is that if I have, for example, 10 players, the foreach will loop 10 times, take each player and bind it into asp-route-data="@player" with it's 3 properties, and after 10 times it will go to my page where when I choose battle and the modal dialogue opens , I choose Confirm and it should send me here asp-controller="Game" asp-action="Battle"
      Well, so it does, but the value passed is null. And workaround anyone? I will be very thankful! I am using HttpGet as an attribute to this Action. Is this the problem?










      share|improve this question













      With this code I am failing to pass PlayerViewModel with model binding to my action method



       @foreach (var player in Model)
      {
      <tr>
      <td><img class="mini-avatar" src="@player.AvatarURL" /></td>
      <td>@player.Username</td>
      <td>@player.XP</td>
      <td><button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Battle!</button></td>

      <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog">

      <div class="modal-content">
      <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title">Commencing Battle</h4>
      </div>
      <div class="modal-body">
      <p>Are you sure you want to fight ?</p>
      </div>
      <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      <a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
      </div>
      </div>

      </div>
      </div>
      </tr>


      Down bellow you can see this code snippet :



      <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      <a class="btn btn-success" asp-controller="Game" asp-action="Battle" asp-route-data="@player" style="background-color:lightblue">Confirm</a>
      </div>


      The problem is that if I have, for example, 10 players, the foreach will loop 10 times, take each player and bind it into asp-route-data="@player" with it's 3 properties, and after 10 times it will go to my page where when I choose battle and the modal dialogue opens , I choose Confirm and it should send me here asp-controller="Game" asp-action="Battle"
      Well, so it does, but the value passed is null. And workaround anyone? I will be very thankful! I am using HttpGet as an attribute to this Action. Is this the problem?







      .net model-view-controller model-binding






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 21:45









      Edwardcho

      13




      13



























          active

          oldest

          votes











          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',
          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%2f53253566%2fmodel-binding-failed-passing-null-value-into-action%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53253566%2fmodel-binding-failed-passing-null-value-into-action%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







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3