Partial is not rendered

0

According to this link of another question of mine that ended up generating error where I followed the steps referring to another question, I'm having a rather strange error.

I created a partial to do the manipulations in the Telephones table of my project. But it simply is not rendered in any way ... It should appear in the create and edit of the student data.

I'll put 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 the 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'm using the BeginCollectionItem package.

    
asked by anonymous 03.11.2014 / 21:06

1 answer

2

Do not use RenderPartial for this case:

Html.RenderPartial("_PartialTelefone", telefone);

Use only Partial and @ ahead:

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

Here I explain why .

    
03.11.2014 / 21:12