2

将自定义 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>
4

1 回答 1

3

Position relative to <![CDATA[ and ]]> is important. I adjusted my snippet:

<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>
于 2012-05-04T17:47:53.727 回答