2012-12-18 28 views
0

我有一个MVC项目,我有一个全局函数返回url的。这里是其中之一:访问资源文件中的全局变量

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace Account.Models 
{ 
    public class ApplicationStrings 
    { 

     public static string ApplicationString(){ 

      return "http://localhost11234/Studentbook"; 

    } 

    } 

} 

我有资源文件,我存储电子邮件正文为不同的电子邮件出去。这是一个嵌入式资源。

如何从我的资源文件中的全局函数中访问URL?

我尝试以下方法,但没有看到链接:

<html> 
<body> 
<br> Student ID : <a href= ApplicationStrings.ApplicationString() + ?id=JD1123>JD1123</a><br>  
</body> 
</html> 

我看到以下内容:

Student ID : JD1123 

这里JD1123是一个链接,该链接带我到“ApplicationStrings.ApplicationString ()“而不是”http:// localhost11234/Studentbook?id = JD1123“

回答

0

您不能做你想做的事,至少不能直接做。资源字符串是静态项目,当您访问它们时不会自动更改。所以基本上,你正准备退出。计算机不够聪明,不知道应该调用一个方法来让你的配置字符串停留在那里。

相反,您需要编写一段中间代码来搜索您的资源字符串以替换特定的项目(可能将它们标记为<%或其他),然后使用Regex.Replace插入正确的文本。这是相当微不足道的。

http://www.codeguru.com/cpp/cpp/string/regex/article.php/c2791/Using-Regular-Expressions-for-SearchReplace.htm