Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using modal pop up for user to enter email and password to login. This is implemented in post method and the issue is I am not getting null in posted values. I have another Get action implementation same view which is working fine. My code is:

@*@*Jquery Dialog Link Starts*@
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Components/ModalDialog/ModalDialogStyle.css" rel="stylesheet" />
@*@*Jquery Dialog Link Ends*@

@*Jquery and Bootstrap library starts*@
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
@*Jquery and Bootstrap library ends*@

@using (Html.BeginForm("SearchRecord", "Home", FormMethod.Get))
{
//this action verb works fine i.e. passe correct value to controller
// some html controls
<input id="btnSubmit" class="btn btn-default" type="submit" value="Submit">
}

Below code block is of modal dialog in which post to controller is getting null value in parameters.

@using (Html.BeginForm("Login", "Home", FormMethod.Post))
   {
       <!-- Bootstrap Modal -->
       <div id="myModal" class="modal fade" role="dialog">
           <div class="modal-dialog">
               <!-- Modal content-->
               <div class="modal-content">
                   <div class="modal-header">
                       <button type="button" class="close" data-dismiss="modal"</button>
                       <h4 class="modal-title">Enter your credentials</h4>
                   </div>
                   <div class="modal-body">
                       <table>
                           <tbody>
                               <tr>
                                   <td>
                                       <input type="text" id="email" placeholder="Email Address" />
                                   </td>
                               </tr>
                               <tr>
                                   <td>
                                       <input type="password" id="password" placeholder="Password" />
                                   </td>
                               </tr>
                               <tr>
                                   <td>
                                       <span id="passwordSpan"></span>
                                   </td>
                               </tr>
                               <tr>
                                   <td>
                                       <input id="btnLogin" class="btn btn-default" type="submit" value="Login">
                                   </td>
                               </tr>
                               <tr>
                                   <td>
                                       <span id="messageSpan"></span>
                                   </td>
                               </tr>
                               <tr>
                                   <td>
                                       <img id="loadingImg" src="loading.gif" />
                                   </td>
                               </tr>
                           </tbody>
                       </table>
                   </div>
                   <div class="modal-footer">
                       <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                   </div>
               </div>
               <!-- END Modal content-->
           </div>
       </div>
       <!-- END Bootstrap Modal -->

   }


Controller Method:
[HttpPost]
public ActionResult Login(string email, string password)
{

return View();
}

In email and password, I am getting null value.

What I have tried:

I tried using
string email = Request.Form["email"];
           string password = Request.Form["password"];
but still got null value.
Posted
Updated 12-Mar-19 6:43am

It's the "name" of the element that is posted to the server and used for model binding, not the id. You can keep the id but add the name as well.

<input type="text" id="email" name="email" placeholder="Email Address" />


If you use the built in @Html helpers they do all of this for you.
 
Share this answer
 
Thanks Sitecore for replying.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900