Question

I really like the bindings feature of spark, it really improves markup but I have come across a small problem. Is it possible to create a spark binding that doesn't have any code in it just html? For example:

    <element name="searchbox">
        <div class="searchbox">
            <input type="text"/>
            <img src="/content/images/cross.png" placeholder="${sharedres.searchplacheolder}"/>
        </div>
    </element>

When I try and render the element searchbox above I get a page render error:

error CS1501: No overload for method 'Write' takes 0 arguments

Is there a way to do this or do can you only provide code in a binding?

Was it helpful?

Solution

You can do it, the whole binding just needs to represent a string like so turn your code into a string and escape all the angle brackets and it should work:

        "&lt;element name=\"searchbox\"&gt;&lt;div class=\"searchbox\"&gt;&lt;input type=\"text\"/&gt;&lt;img src=\"/content/images/cross.png\" placeholder=\"@placeholder\"/&gt;&lt;/div&gt;&lt;/element&gt;"

having said that, you might be better off placing something like this in a partial view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top