MVCプロジェクトでは、以下のコードでデータを取得しようとしています。私の問題は構文エラーですmvcビューのネストされた引用状況
@functions{
string GetRootRowHtml(List<CORE.Models.Category> categories, int parentId)
{
string html = String.Empty;
foreach (var category in categories.Where(c => c.ParentId == parentId))
{
var childList = GetRootRowHtml(categories, category.Id);
var categoryHtml = "<li class=\"dd-item\" data-id=\"" + category.Id + "\" data-role=\"collapsible\" data-iconpos=\"left\" data-inset=\"false\">";
categoryHtml += "<div class=\"dd-handle dd-nodrag\">";
categoryHtml += "<div style=\"margin: 0 10px; width:25px; height:25px; float: left;\"></div>";
categoryHtml += "<span class=\"label label-info\"><i class=\"fa fa-arrows\" ></i></span>" + category.Name.Replace("'", @"\'") +
"</div>" +
"<span class=\"pull-right menu_process\">";
if (CORE.Models.User.IsAllowedTo(CORE.Models.User.AccessType.CATEGORY_UPDATE))
{
categoryHtml += "<button class=\"btn btn-primary btn-circle\" onClick=\"UpdateCategory(" + category.Id + ")\" style =\"margin-right:10px;\" type=\"button\" title =\"" + Resources.Resource.Edit + "\"> <i class=\"fa fa-edit\"></i></button>";
categoryHtml += "<button class=\"btn btn-success btn-circle\" onClick=\"ShowCategory(" + category.Id + ",\""+ category.Name + "\")\" style =\"margin-right:10px;\" type=\"button\" title =\"" + Resources.Resource.Edit + "\"> <i class=\"fa fa-list\"></i></button>";
}
html += categoryHtml;
}
return html;
}
}
上記のコードでは、以下のコード行に構文エラーがあります。
categoryHtml += "<button class=\"btn btn-success btn-circle\" onClick=\"ShowCategory(" + category.Id + ",\""+ category.Name + "\")\" style =\"margin-right:10px;\" type=\"button\" title =\"" + Resources.Resource.Edit + "\"> <i class=\"fa fa-list\"></i></button>";
エラーは、このために
以下の理由が引用符です。 onclickメソッドにはquatoがあり、onclick関数のパラメータに文字列のためのquatoもあります。私はたくさん試しましたが、解決策を見つけることができませんでした。 この問題を解決するにはどうすればよいですか?Uncaught SyntaxError: Unexpected token }
ありがとうございます。
私が試したが、働いていません。 –