Click here to Skip to main content
14,448,968 members
Rate this:
Please Sign up or sign in to vote.
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 7:43am
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Thanks Sitecore for replying.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100