我在umbraco局部视图中有如下代码。即使{}对匹配,它也会显示错误,即}}。
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var langstr = "All";
var pageSize = 6;
var max_pages=0;
try
{
if (@ViewData["storylang"] == null)
{
langstr = "";
}
else
{
langstr = @ViewData["storylang"].ToString();
}
}
catch (Exception ex)
{
langstr = "";
}
var pageIndex = (int)@ViewData["page_index"];
dynamic selected;
if (@ViewData["curpage"] != null)
{
var id = (int)@ViewData["curpage"];
var currentNode = Umbraco.TypedContent(id);
selected = currentNode.Children.Where("Visible");
if(langstr != ""){
selected = currentNode.Children.Where("Visible").Where("language=\"" + @langstr + "\"");
max_pages = currentNode.Children.Count();
<ul>
@foreach (var story in selected.Take(pageIndex * pageSize))
{
<li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story.Url" class="\""st-text"\">@story.Name</a></li>
}
</ul>
}
}
else
{
selected = CurrentPage.Children.Where("Visible");
max_pages = CurrentPage.Children.Count();
if(selected.Any()){
<ul>
@foreach (var story1 in selected.Take(pageIndex * pageSize))
{
<li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story1.Url" class="st-text">@story1.Name</a></li>
}
</ul>
}
}
}
代码有什么问题?谁能解决同样的问题?我哪里错了?我花了很多钱。
答案 0 :(得分:0)
你有两个问题。
首先,这个:
Activity
阻止正确解析该行并弄乱以下内容。你可能意味着
findViewById(R.id.btn_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Test", Toast.LENGTH_SHORT).show();
}
});
或
class="\""st-text"\"
然后,已经在C#代码上下文中的所有class="st-text"
必须仅用class='"st-text"'
替换(全部都是这样)。
答案 1 :(得分:0)
我解决了这个问题。它是混合代码和渲染块...... 所以这是解决方案。
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var langstr = "All";
var pageSize = 6;
var max_pages=0;
try
{
if (ViewData["storylang"] == null)
{
langstr = "";
}
else
{
langstr = ViewData["storylang"].ToString();
}
}
catch (Exception ex)
{
langstr = "";
}
var pageIndex=1;
if(ViewData["page_index"]!=null)
{
pageIndex= (int)@ViewData["page_index"];
}
dynamic selected;
}
@if (ViewData["curpage"] != null){
var id = (int)ViewData["curpage"];
var currentNode = Umbraco.TypedContent(id);
selected = currentNode.Children.Where("Visible");
if(langstr != ""){
selected = currentNode.Children.Where("Visible").Where("language=\"" + @langstr + "\"");
max_pages = currentNode.Children.Count();
<ul>
@foreach (var story in selected.Take(pageIndex * pageSize))
{
<li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story.Url" class="st-text">@story.Name</a></li>
}
</ul>
}
else{
selected = currentNode.Children.Where("Visible");
max_pages = currentNode.Children.Count();
<ul>
@foreach (var story in currentNode.Children.Where("Visible").Take(pageIndex * pageSize))
{
<li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story.Url" class="st-text">@story.Name</a></li>
}
</ul>
}
}
else
{
selected = CurrentPage.Children.Where("Visible");
max_pages = CurrentPage.Children.Count();
if (selected.Any())
{
<ul>
@foreach (var story in selected.Take(pageIndex * pageSize))
{
<li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story.Url" class="st-text">@story.Name</a></li>
}
</ul>
}
}
答案 2 :(得分:-1)
比较你的主视图的所有开始和结束括号。
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var langstr = "All";
var pageSize = 6;
var max_pages=0;
try
{
if (ViewData["storylang"] == null)
{
langstr = "";
}
else
{
langstr = ViewData["storylang"].ToString();
}
}
catch (Exception ex)
{
langstr = "";
}
var pageIndex = (int)ViewData["page_index"];
dynamic selected;
if (ViewData["curpage"] != null)
{
var id = (int)ViewData["curpage"];
var currentNode = Umbraco.TypedContent(id);
selected = currentNode.Children.Where("Visible");
if(langstr != "")
{
selected = currentNode.Children.Where("Visible").Where("language=\"" + @langstr + "\"");
max_pages = currentNode.Children.Count();
<ul>
@foreach (var story in selected.Take(pageIndex * pageSize))
{
<li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story.Url" class="st-text">@story.Name</a></li>
}
</ul>
}
}
else
{
selected = CurrentPage.Children.Where("Visible");
max_pages = CurrentPage.Children.Count();
if(selected.Any()){
<ul>
@foreach (var story1 in selected.Take(pageIndex * pageSize))
{
<li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story1.Url" **class="st-text"**>@story1.Name</a></li>
}
</ul>
}
}
}