1
@{
    Layout = null;
    string root = Server.MapPath("~");
    string path = @"Content\galleries\galleries\";
    DirectoryInfo Dir = new DirectoryInfo(root + path + (string)ViewData["Name"]);
    FileInfo[] FileList = Dir.GetFiles("*.jpg");
    string response = "";
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <script type="text/javascript">
        jQuery(function ($) {

            var array = new Array();
            var galleryname = '@ViewData["Name"]';

            @for (int i = 0; i < FileList.Length; i++)
            {
                string s = @"
                var path = '../Content/galleries/galleries/" + @ViewData["Name"] + @"/" + @FileList[i].Name + @"';
                var thumbpath = '../Content/galleries/galleries/" + @ViewData["Name"] + @"/thumbs/" + @FileList[i].Name + @"';
                array[" + i.ToString() + @"] =
                    {
                        image: path,
                        title: '" + @ViewData["Name"] + @"',
                        thumb: thumbpath,
                        url: path
                    };";
                response += s;
            }
            @response

これは私のコードです。asp.net を使用して動的に JavaScript コードを記述したいと考えています。文字列 'response' を @response で出力すると、ページ ソースですべての ' 文字が & #39; に変更されていることがわかります。. その場合、すべてのパスが悪いです。また、ループ内で Response.Write(s) を使用してみましたが、' 文字は変更されませんが、生成されたコードはページ ソースの最初の doctype の前に配置され、もちろん何も機能しません。

これらの問題を解決するにはどうすればよいですか? またはそれらの少なくとも 1 つ ;) ? それとも別の方法がありますか?

4

1 に答える 1