How do you bind Polymer elements to a Model in ASP.NET

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 17:26:07

问题


I have no problems displaying my model in a View using Polymer, for example:

        <paper-icon-item>
            <iron-icon icon="communication:phone" item-icon></iron-icon>
            <paper-item-body two-line>
                <div>@Model.PhoneNumber</div>
                <div secondary>Phone Number</div>
            </paper-item-body>
        </paper-icon-item>

but I just do not get the bindings right for input

    //this does not work
    <paper-input label="Phone Number">@Model.PhoneNumber</paper-input>

    //nor this
    <paper-input is="iron-input" label="Phone Number">@Model.PhoneNumber</paper-input>

    //even when I try adding this...
    <script>
        Polymer({
        })
    </script>

...plus a myriad of other attempts. The bindings are not working one or two way (I cannot display existing data or update data)

The controls look correct, they are very cool, animated, etc


回答1:


You could bind to the value property of the paper input

<paper-input is="iron-input" label="Phone Number" value="@Model.PhoneNumber" name="PhoneNumber"></paper-input>

And also, for getting the value back to the server (if you are posting your form to the server), you might want to add the name attribute to your input, so that MVC will know how to bind your input to the model property.




回答2:


You set the text of paper-input by using the value property. Try this

<paper-input label="Phone Number" value="@Model.PhoneNumber"></paper-input>
<paper-input is="iron-input" label="Phone Number" value="@Model.PhoneNumber"></paper-input>


来源:https://stackoverflow.com/questions/34815159/how-do-you-bind-polymer-elements-to-a-model-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!