0

I have a main page:

@model List<NovoRelatorioWeb.Controllers.HomeController.Campo>

@{
    ViewBag.Title = "Relatorio";
}

<div id="RelatorioTablet">
    <div class="container">
        <div class="row">
            <div class="col-lg-8">

                <div class="row">
                    <div class="col-sm-12">
                        @if (Model != null)
                        {
                            <span>
                                Relatório ELO > Versão 2.0 > @Model[0].Relatorio
                            </span>
                        }
                    </div>
                </div>

                <hr style="border: 1px solid orangered" />

                <div class="row">

                    <div class="col-sm-2">
                        <br />
                        <input type="button" id="butSalvar" class="form-control" style="background-color:orangered" value="Salvar" />
                    </div>
                </div>
                <hr style="border: 1px solid orangered" />

            </div>
            <div class="col-lg-4">
                <div>
                    @Html.Partial("~/Views/Home/PhonePreview.cshtml", Model)
                </div>
            </div>
        </div>
    </div>

</div>

@section scripts {
    <script src="~/Scripts/relatorio_elo.js" type="text/javascript"></script>

}

and it calls another page:

@model List<NovoRelatorioWeb.Controllers.HomeController.Campo>

@{
    Layout = null;
}

<div>

    <div id="PhonePreview" style="border:1px solid black;font-size:20px;">

        @if (Model != null)
        {
            <div class="container1" style="background-color:orangered;padding-top:5px;padding-bottom:5px;">
                <div class="row" style="text-align:center;width:100%;">
                    <div class="col-sm-12" > 
                        <span style="color:white;">
                            @ViewBag.Relatorio
                        </span>
                    </div>
                </div>
            </div>

            foreach (var campo in Model)
            {
                if (campo.Tipo == "Text")
                {                   
                    @Html.Partial("~/Views/Home/Controles/Text.cshtml", campo)                    
                }

            }
        }
    </div>
</div>

<style>
    input[type=date]::-webkit-inner-spin-button {
        -webkit-appearance: none;
        display: none;
    }
</style>

and it calls

@model NovoRelatorioWeb.Controllers.HomeController.Campo

<div class="1" style="padding-top:5px;padding-bottom:5px;">
    <div class="row">
        <div class="col-sm-5">
            <span style="padding-left:5px;">
                @Model.Nome:
            </span>
        </div>
        <div class="col-sm-7" style="text-align:right;">
            <input type="text" style="width:100%;" />
        </div>
    </div>
</div>

and im calling the controller via jquery ajax

 var urlService = "/Home/Salvar";
    var jsonobj = CriaArrayCampos();
    jsonobj = JSON.stringify(jsonobj)

    $.ajax({
        url: urlService,
        type: 'POST',
        data: jsonobj,
        datatype: 'json',
        contentType: 'application/json',
        beforeSend: function () {

        },
        complete: function () {

        }
    });

It means, a page who calls a partial view, and a partial view inside. OIk, everything works, but when i click save button, i call the controller, who returns a list with objects to update the partial view (i only update the name).. But dont update.. but im making with razor... I have tested and the values comes to the partial view... how can i achieve this?

thanks so much!

Rafael

Rafael Spessotto
  • 111
  • 1
  • 4
  • 14
  • Can you show the controller action code which is getting called ? and i dont't see any form in your page, how are you posting model back to controller? – Ehsan Sajjad Nov 28 '17 at 18:58
  • @EhsanSajjad i have updated the question – Rafael Spessotto Nov 28 '17 at 19:15
  • If you put an `console.log` on your Json return, did you get any elements? If yes, then the problem is on your code that implements the new Objects? What are you doing when that Ajax succeed? – Matheus Cuba Nov 28 '17 at 19:45
  • i think im know the error but dont know how to resolve.....because im calling the controller via ajax..The controller is called and calls the view..so i dont make nothing with the ajax return... – Rafael Spessotto Nov 28 '17 at 19:53
  • maybe is this why dont update the partial view...? – Rafael Spessotto Nov 28 '17 at 19:53
  • There are multiple errors with your code. First your input does not even have a `name` attribute so it does not post a value. And you cannot use a partial for collection items (unless you pass the `HtmlFieldPrefix` so that collection indexers are added to you `name` attribute). Suggest you start by reading [this answer](http://stackoverflow.com/questions/30094047/html-table-to-ado-net-datatable/30094943#30094943) to understand how to generate you view correctly –  Nov 28 '17 at 21:57
  • Thanks for the answer @StephenMuecke.. I will read..but im trying to call the controller by ajax, whats is working...The view receive the parameter and works perfectly..What is not working is the partial view who not updates...When i debug, i see the new value in the razor..Just dont update in the screen....but i will read the answer..thanks again! – Rafael Spessotto Nov 29 '17 at 11:21
  • Nowhere in your script do you ever do anything with the response you get back from the server –  Nov 29 '17 at 11:23
  • Yes, i think this is my erorr...But how can i call the controller sending a javascript array (is my list of objects) and the controller calls the view and updaste the values? – Rafael Spessotto Nov 29 '17 at 11:24
  • @RafaelSpessotto, I dint even know what your `Salvar()` method does or returns, but your get it in the ajax success callback, and then you can do something with it, e.g. `success: function(response) { $(someElement).html(response); }` if your returning some html. –  Nov 29 '17 at 23:06
  • @StephenMuecke my problem is how to send the javascript object to the controller via ajax and get the return model and update the div.. – Rafael Spessotto Nov 30 '17 at 11:49
  • The Salvar() method returns a list of my object.. – Rafael Spessotto Nov 30 '17 at 11:50
  • I have already explained how to update the DOM in the ajax `success` callback. And as far as sending the javascript object to the client, I have no idea what your `CriaArrayCampos()` function does. –  Dec 01 '17 at 00:29

0 Answers0