Visual Studio代码段文字替换过早结束

时间:2012-05-03 23:58:57

标签: visual-studio-2010 code-snippets literals replace

将自定义HTML代码段插入MVC视图时,当我开始键入值时,文字替换的编辑将结束。

我错过了什么吗?

我的文字用于替换属性名称两次:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <Header>
        <Title>MVC Field Pair</Title>
        <Shortcut>mvcfieldpair</Shortcut>
        <Description>Inserts an MVC label/input pair</Description> 
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType> 
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal Editable="true">
                <ID>property</ID>
                <ToolTip>Model property</ToolTip>
                <Default>myProperty</Default>
            </Literal>
        </Declarations>
        <Code Language="html">
            <![CDATA[
                <li>
                    <%= Html.LabelFor(m => m$property$) %>
                    <%= Html.TextBoxFor(m => m$property$) %>
                </li>
            $end$]]>
        </Code>
    </Snippet>
</CodeSnippet>

1 个答案:

答案 0 :(得分:3)

相对于<![CDATA[]]>的位置非常重要。我调整了我的片段:

<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <Header>
        <Title>MVC Field Pair</Title>
        <Shortcut>mvcfieldpair</Shortcut>
        <Description>Inserts an MVC label/input pair</Description> 
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType> 
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>property</ID>
                <ToolTip>Model property</ToolTip>
                <Default>myProperty</Default>
            </Literal>
        </Declarations>
        <Code Language="html"><![CDATA[<li>
    <%= Html.LabelFor(m => m$property$) %>
    <%= Html.TextBoxFor(m => m$property$) %>
</li>$end$]]></Code>
    </Snippet>
</CodeSnippet>