Partial is not rendered

Asked

Viewed 101 times

0

Accordingly this link from another question of mine that ended up generating error where I followed the steps referring to another question, I am experiencing a rather strange error.

I created a partial to make the manipulations in the Phones table of my project. Only that simply it is not rendered in any way... She should appear in views of create and Edit of the student’s data.

I’ll put in the codes I used:

View Create( and that of Edit, which is the same thing)

@model SisGAL.Models.Aluno

@{
   ViewBag.Title = "Create";
}

<h2>Create</h2>


@using (Html.BeginForm()) 
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>Aluno</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.TipoEnsino, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.TipoEnsino, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.TipoEnsino, "", new { @class = "text-danger" })
        </div>
    </div>

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

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

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

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

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

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

    <div class="form-group">
        @if (Model != null && Model.Telefones != null)
        {
            foreach (var telefone in Model.Telefones)
            {
                Html.RenderPartial("_PartialTelefone", telefone);
            }
        }
    </div>

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

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

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

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

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

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

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>
</div>
}

<div>
 @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

Partial of phones

@model SisGAL.Models.Telefone

@{
Layout = null;
}

@using (Html.BeginCollectionItem("Telefones"))
{
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.AlunoId)
@Html.EditorFor(model => model.Numero)
@Html.EnumDropDownListFor(model => model.TipoTelefone)
}

Note: I am using the Begincollectionitem package.

  • You entered at least one empty phone into the student by Controller?

  • Couldn’t get it in controller why it is not rendered to div. I put it right in my hand, right there in the bank table and I referenced the id student. And yet nothing...

1 answer

2


Do not use RenderPartial for this case:

Html.RenderPartial("_PartialTelefone", telefone);

Use only Partial and with the @ in front:

@Html.Partial("_PartialTelefone", telefone);

Here I explain why.

  • But it still didn’t work. There was nothing !

  • @Érikthiago You even put a breakpoint here to see what happens? @if (Model != null && Model.Telefones != null). I suspect it doesn’t even reach Partial’s rendering code.

  • Look, I didn’t. But I’m sure it’s not enough, because the partial doesn’t show up at all. And if I try to access it via URL, of which there is no page

  • @Érikthiago Yes, because it is a Partial. It is not accessible via URL. It is in the link I put in the reply. Redo the test with breakpoint, please.

  • That one partial must be inside the views of the right student ? I refiz, and there appeared nothing.

  • Generates this: 'Model != null && Model.Phones != null | false'. That is to say, null... What madness.

  • I think it’s the case that you inspect the Model and its attributes.

  • The phone model ?

  • 1

    @Érikthiago The Student Model.

  • But I did like you put there on the other question. What could be wrong ?

  • I don’t know. I think Debug is missing in that.

  • Got it. I’ll see what I can do here

Show 7 more comments

Browser other questions tagged

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