Send model to PartialView with $ .load

0

I'm here because I have a small problem with handling a Model between View and% PartialView

The question is the following, I have a view (that fulfills the form), so as not to overload it so aggressively, add a PartialView that is shown as a modal where I find some more input

I leave an image so that I can easily interpret what I'm trying to do,

The issue is as follows, the form works perfectly, the values reach the controller when sending it, in this case there is no problem, the conflict occurs in case the ModelState is not valid, and in the controller has to do return View(objModelo)

Because in doing so, the information simply does not reach the modal window, I assume this is because the object did not pass.

This is handled in the following way:

HTML

 <div class="modal fade" id="ModalRegulacion" tabindex="-1" role="dialog" aria-labelledby="ModalRegulacionLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Generación Regulación.</h5>
                    <hr />
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body" id="regulacion-body">

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-warning" data-dismiss="modal"><i class="fas fa-step-backward"></i>  Volver</button>
                    <button type="button" class="btn btn-primary guardar">Guardar <i class="fas fa-save"></i></button>
                </div>
            </div>
        </div>
    </div>

JavaScript

 $(document).ready(function () {
      $('#regulacion-body').load('@Url.Action("_Regulacion")');            
 });

The method I use generates the conflict that the return values of the controller are not reaching the PartialView , I leave an image to be interpreted better

Here it looks like in the original form, the EditorFor() is filled with the data returned by the controller, instead the PartialView no.

I know that there are methods to perform the rendering of a PartialView natives of Razor ;

Try using

@{
   Html.RenderPartial("_Regulacion", Model);
}

Where data handling works correctly (because I actually pass the model), the problem is that when rendering it in this way, jQuery is not defined in PartialView

Because of this, I would love to continue using the $.load or some similar method, however, I am open to the possibility of using RenderPartial() if I achieve that jQuery is defined.

Clarification: both, View and PartialView use the same model.

I hope my question has been understood, it may be that it has been a bit farfetched!

Thank you very much for your time and I hope that someone can orient me a little bit with the handling of these situations!

Greetings!

    
asked by Juan Salvador Portugal 24.05.2018 в 14:24
source

0 answers