Bchir Med Amine
Bchir Med Amine

Reputation: 88

getting value of dropdownlist using vue.js

I'm trying to get the value of a drop down list and change the div content using a get request view

 <div class="row row-mb2" id="Produit-tab">
 @Html.DropDownList("Version", new SelectList(ViewBag.Versions, "IdVersion", "VersionProduit"), new { @id = "version" })
 </div>

<div id="versiondetails"></div>

script :

 $.Produit.settingsView = new Vue({
            el: '#Produit-tab',
            data:
                {
                version:''
                },
            watch: {
                version: function (versionprod) {
                    $.get("@Url.Action("Details", "VersionProduit", new {id = "_PARAM_" })".replace("_PARAM_", versionprod), function (data) {

                        $('#VersionDetails').html(data);
                    });
                }
            }//,.....rest of the code 

I'm usually using vue.js with input using v-model="..." but with razor i can't inject a vue.js attribut i tried this but it razor doesn't accept it

 @Html.DropDownList("Version", new SelectList(ViewBag.Versions, "IdVersion", "VersionProduit"), new { @id = "version" ,@v-Model="version" })

Upvotes: 1

Views: 2012

Answers (1)

Sagar Shinde
Sagar Shinde

Reputation: 160

use @v_model insted of @v-Model it will solve your problem.

@Html.DropDownList("Version", new SelectList(ViewBag.Versions, "IdVersion", "VersionProduit"), new { @id = "version" ,@v_model="version" })

Upvotes: 2

Related Questions