[RESOLVED]Pop Up not posting data to controller

Hi! I am pretty new to ASP.NET MVC5, and I am dealingwith something strange,

I have a view , displaying some data from the model that the controller returns (a, b, c), and threeHidden fields with those values.

@using (Ajax.BeginForm("Registro", "Experiencias", null, new AjaxOptions { HttpMethod = "POST", OnSuccess = "detalleSuccess" }, new { id = "DetalleForm", name="DetalleForm" }))
{
    
    @Html.Hidden("idExperiencia", Model.a)
    @Html.Hidden("exclusiva", Model.b)
    @Html.Hidden("idPregunta", Model.c)
    <div class="texto">
         <h2 class="titulo">@Model.a</h2>
         <p class="font_18">@Model.b</p>
         <p class="font_18">@Model.c</p>
    </div>
    <div class="row_derecha">
       <a href="#" class="boton_azul pos_abajo basic6" onclick="ParticiparModal('modal-popup')">Show</a>
    </div>


    <div id="modal-popup" style="display: none;">
         <div class="campo_datos ">
              @Html.TextBoxFor(model => Model.email, new { @class = "input_popup", id = "email", name="correoElectronico"})
         </div>
         <div class="container_boton_condiciones submitbutton" data-form-name="DetalleForm"><a class="boton_grande naranja" href="#">Send</a></div>
    </div>

In the view there is a link that opens the pop up "modal-popup". This pop up has a text box where the user must enter an email address and it is supoosed to be stored in the model.email field. Then if you click in the Send button, the form is submitted.

The problem is that the POST controller action receives a Model object but it is allways null, I think it’s because the model is quite complicated, it has a list inside it and some other objects, and the model binder does not know how to translate it, so
I want to do a Model Binder.

To do it I look at the POST action that is sent by the form (with firebug)  and I see that in the POST action it only sends the hidden fields that are outside of the pop up, in this case it only sends "idExperiencia", "exclusiva" and "idPregunta", I have
tried to add a hidden field in the pop up but it doesn’t appear in the post parameters.

Do you have any idea why the post action is only sending the hidden fields of the main page?

I hope somebody could help me

Thanks!

Post your entire view and model please

you don’t say which modal framework you are using, but most move the modal content to end of the body to make the css work. of course after this, the field is no longer in the form. you need to put the form in the modal, or write javascript to move the modal
back (may need to modify css to get this to work).

 

Leave a Reply