Several editable attributes on html element

Vote:
 

I have an html element (input) that contains several html attributes (placeholder and two data- attributes to show info if element is empty or that input is not valid). I need to make these attributes editable, but I only found Html.EditAttributes helper, which allows me to edit ONE attribute from the list. Is there a way to make sereval attributes editable simultaneously?

#209071
Nov 07, 2019 9:59
Vote:
 

You can do like this

@if (PageEditing.PageIsInEditMode)
{
    @Html.PropertyFor(x => x.AttributeProperty1)
    @Html.PropertyFor(x => x.AttributeProperty2)
    @Html.PropertyFor(x => x.AttributeProperty3)
}
else
{
    <input type="text" data-attr1="@Model.AttributeProperty1" data-attr1="@Model.AttributeProperty2"  data-attr1="@Model.AttributeProperty3" />
}

It's just a sample code as hint, you can modify as your need. Ultimately the solution is to use the PageEditing.PageIsInEditMode

#209083
Nov 07, 2019 11:33
Vote:
 

Great! I didn't think about checking editing mode but this solution does exactly what I had needed. Thanks!

#209086
Nov 07, 2019 12:12
Praful Jangid - Nov 07, 2019 13:01
Your welcome :)