How to structure the partialView To make the modelBinder correctly?

Asked

Viewed 27 times

0

I have a form that was broken using partial view, there is only one Create for all of them, and then I think there is nothing wrong, when trying to submit the form I got the following error..... `

Sqlexception: The INSERT statement conflicted with the FOREIGN KEY Constraint "Fk_dbo.Laudoes_dbo.Developments". The Conflict occurred in database "Engosengenhariacontext-20180626101342", table "dbo. Enterprises", column 'Enterprise'. The statement has been terminated.

After searching a little I discovered that the object is being passed empty, we come here the main question, whether I have a number x of partitions views, and I need to send this data all together, how do I do? every page of these partials has to have the .....

@using (Html.BeginForm("Create","Laudos"))
{
    @Html.AntiForgeryToken()

? o only the final partial that has the create button needs to have this?

follows an example, basically all partials follow this structure. I hope you have made me understand, Since grateful

@using (Html.BeginForm("Create","Laudos"))
{
    @Html.AntiForgeryToken()

<div class="panel-body">
    <div class="row">
        <div class="form-group">
            <div class="col-lg-6">
                <label>Interessado</label>
                <input class="form-control" type="text" name="nome_empreendimento" placeholder="Nome do empreendimento deverá aparecer aqui..." readonly>
            </div>

        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header"></h3>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="form-horizontal">
            <div class="form-group">
                @Html.LabelFor(model => model.Finalizacao_Laudo.Observacao, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Finalizacao_Laudo.Observacao, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Finalizacao_Laudo.Observacao, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Finalizacao_Laudo.AcompanhouVistoria, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Finalizacao_Laudo.AcompanhouVistoria, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Finalizacao_Laudo.AcompanhouVistoria, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Finalizacao_Laudo.AcompanhanteId, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Finalizacao_Laudo.AcompanhanteId, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Finalizacao_Laudo.AcompanhanteId, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Finalizacao_Laudo.Contato, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Finalizacao_Laudo.Contato, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Finalizacao_Laudo.Contato, "", new { @class = "text-danger" })
                </div>
            </div>

            <div id="tipo" class="form-group">
                @Html.LabelFor(model => model.Finalizacao_Laudo.TipoDoAcompanhante, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EnumDropDownListFor(model => model.Finalizacao_Laudo.TipoDoAcompanhante, htmlAttributes: new { @class = "form-control", onchange = "outros()" })
                    @Html.ValidationMessageFor(model => model.Finalizacao_Laudo.TipoDoAcompanhante, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Finalizacao_Laudo.Outro, htmlAttributes: new { @class = "control-label col-md-2", style = "Display: none", id = "label" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Finalizacao_Laudo.Outro, new { htmlAttributes = new { @class = "form-control", style = "Display: none" } })
                    @Html.ValidationMessageFor(model => model.Finalizacao_Laudo.Outro, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Finalizacao_Laudo.DataVistoria, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Finalizacao_Laudo.DataVistoria, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Finalizacao_Laudo.DataVistoria, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>
    </div>
    <br />
    <br />
    <div>
        <a href="#tab_1_6" data-toggle="tab" class="btn btn-success">Seguinte</a>
        <input type="submit" value="Create" class="btn btn-default" />
    </div>
</div>  

}


}
  • 4

    I think you need to have the form only in the main view, the partial view you don’t need to put all the way you need to bind your data to the partial type @Html.Renderpartial("Nameanew", model)

  • 1

    As Marcos said, you should only have one form and all the values you want to pass to the controller should be inside the form, that is, your partial views should be inside this single form.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.