Asp.net mvc HTML&;ASP MVC 4:错误CS1056:意外字符'\';

Asp.net mvc HTML&;ASP MVC 4:错误CS1056:意外字符'\';,asp.net-mvc,html,asp.net-mvc-4,escaping,Asp.net Mvc,Html,Asp.net Mvc 4,Escaping,我使用的是asp MVC4。我有以下html标记 <input type="text" maxLength="2000" pattern="^(~/|https?://).*$|^mailto:([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" > 您还可以将模式属性的值用作字符串文字: <input type="text" maxLength="2000" pattern='@(@"^(~/|https?://).*$|^mailto:([\w\

我使用的是asp MVC4。我有以下html标记

<input type="text" maxLength="2000" pattern="^(~/|https?://).*$|^mailto:([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" >

您还可以将模式属性的值用作字符串文字:

<input type="text" maxLength="2000" pattern='@(@"^(~/|https?://).*$|^mailto:([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$")' >

//better:    
@{
    const string urlPattern = @"^(~/|https?://).*$|^mailto:([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
    }
<input type="text" maxLength="2000" pattern="@urlPattern" >

//更好:
@{
常量字符串urlPattern=@“^(~/| https?:/).$^mailto:([\w\.-]+)@([\w\-]+)((\.(\w){2,3})+$”;
}
<input type="text" maxLength="2000" pattern='@(@"^(~/|https?://).*$|^mailto:([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$")' >

//better:    
@{
    const string urlPattern = @"^(~/|https?://).*$|^mailto:([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
    }
<input type="text" maxLength="2000" pattern="@urlPattern" >