Pass values in razor to javaScript

0

I'm doing an application in asp.net, what happens is that I need to access a value that the razor brings me, to later use it in a script but I do not know how to combine razor in javascript, I know that from javascript to razor not it is possible but from razor to javascript yes. I need to pass a value that @model brings to my switch.

@model IEnumerable<MvcFrontBolsaTrabajo.Models.ParaProcReportes.PostulacionesXCandidatoModel>

@ {     Layout="~ / Views / Shared / _LayoutCandidate.cshtml"; }

@ {     ViewBag.Title="XCandidate Postulations"; }

    @foreach (var item in Model)
    {

            <div class="panel panel-primary" style="display:inline-block; text-align:center; margin-right:5%;">
                <div class="panel-heading">
                    @Html.DisplayFor(modelItem => item.TituloVacante)
                </div>
                <p>
                    @Html.DisplayFor(modelItem => item.Nombresoc)
                </p>
                <p>
                    @Html.DisplayFor(modelItem => item.Nombreciu)
                </p>
                <p>
                    @Html.DisplayFor(modelItem => item.FechaPostulacionvc)
                </p>
                <div class="second circle"></div>
                <strong>

                </strong>
            </div>

    }

@section Scripts {

<script>

    switch () {
        case 25:
            $("#divMisPostulaciones").removeClass("SubMenuCandidato");
            $("#divMisPostulaciones").addClass("SubMenuCandidatoB");


            $('.second.circle').circleProgress({
                value: 1,
                startAngle: -Math.PI / 2,
                reverse: true,
                progress: 1.0
            }).on('circle-animation-progress', function (event, progress) {
                var contador = Math.round(100 * progress);
                if (contador == 25) {
                    $('div').find('strong').html(Math.round(100 * progress) + '<i>% CV visto</i>')
                };
            });
            break;

        case 50:
            $("#divMisPostulaciones").removeClass("SubMenuCandidato");
            $("#divMisPostulaciones").addClass("SubMenuCandidatoB");


            $('.second.circle').circleProgress({
                value: 1,
                startAngle: -Math.PI / 2,
                reverse: true,
                progress: 1.0
            }).on('circle-animation-progress', function (event, progress) {
                var contador = Math.round(100 * progress);
                if (contador == 25) {
                    $('div').find('strong').html(Math.round(100 * progress) + '<i>% CV visto</i>')
                };
            });

            break;

    }
</script>

}

    
asked by Roberto Dominguez 16.06.2017 в 18:51
source

2 answers

1

You can access in this way

var modelo = @Html.Raw(Json.Encode(Model));

So you have all the values of your model in a javascript variable with JSON format, so you can access

modelo.TituloVacante
    
answered by 16.06.2017 / 18:59
source
0

Add it to the page with input hidden like this:

@Html.HiddenFor(model => model.Property)
    
answered by 16.06.2017 в 19:02