0

我在 asp .net mvc helper 函数中遇到了意外的 pharantesis 错误。一切似乎都很好,它给出了一个“}”错误。

@helper GetirIcerikStil(string anaMenuKontrol, string solMenuKontrol, string sekmeKontrol, UrlHelper url){
var d = DateTime.Now;
var tazele = d.ToLongTimeString();

anaMenuKontrol = BuyutIlkHarf(anaMenuKontrol);
solMenuKontrol = BuyutIlkHarf(solMenuKontrol);
sekmeKontrol = BuyutIlkHarf(sekmeKontrol);

var href1 = string.IsNullOrEmpty(anaMenuKontrol) ? "" : @url.Content("~/_Docs/SoruCevap/" + anaMenuKontrol + "/_Stil/Index.less?" + @tazele);
var href2 = string.IsNullOrEmpty(solMenuKontrol) ? "" : @url.Content("~/_Docs/SoruCevap/" + anaMenuKontrol + "/" + solMenuKontrol + "/_Stil/Index.less?" + @tazele);
var href3 = string.IsNullOrEmpty(sekmeKontrol) ? "" : @url.Content("~/_Docs/SoruCevap/" + anaMenuKontrol + "/" + solMenuKontrol + "/" + sekmeKontrol + "/_Stil/Index.less?" + @tazele);

if (string.IsNullOrEmpty(href1))
{
    <link href="@href1" class="icerikStil anaMenu" rel="stylesheet" type="text/css" />

    if (string.IsNullOrEmpty(href2))
    {
        <link href="@href2" class="icerikStil solMenu" rel="stylesheet" type="text/css" />

        if (string.IsNullOrEmpty(href3))
        {
            <link href="@href3" class="icerikStil sekme" rel="stylesheet" type="text/css" />
        }
    }

    <link href="#" id="icerikStilPozisyonu" />
}
}

第 32 行在浏览器中产生的错误是:

    Compiler Error Message: CS1513: } expected

Source Error:


Line 30:         
Line 31:         <link href="#" id="icerikStilPozisyonu" />
Line 32:     }
Line 33: }
Line 34:
4

1 回答 1

0

我解决了剃刀功能的问题,例如:

@functions
{
    public static string GetirIcerikStil(string anaMenuKontrol, string solMenuKontrol, string sekmeKontrol, UrlHelper url)
    {
        var d = DateTime.Now;
        var tazele = d.ToLongTimeString();

        anaMenuKontrol = BuyutIlkHarf(anaMenuKontrol);
        solMenuKontrol = BuyutIlkHarf(solMenuKontrol);
        sekmeKontrol = BuyutIlkHarf(sekmeKontrol);

        var href1 = string.IsNullOrEmpty(anaMenuKontrol) ? "" : @url.Content("~/_Docs/SoruCevap/" + anaMenuKontrol + "/_Stil/Index.less?" + @tazele);
        var href2 = string.IsNullOrEmpty(solMenuKontrol) ? "" : @url.Content("~/_Docs/SoruCevap/" + anaMenuKontrol + "/" + solMenuKontrol + "/_Stil/Index.less?" + @tazele);
        var href3 = string.IsNullOrEmpty(sekmeKontrol) ? "" : @url.Content("~/_Docs/SoruCevap/" + anaMenuKontrol + "/" + solMenuKontrol + "/" + sekmeKontrol + "/_Stil/Index.less?" + @tazele);

        var link1 = string.IsNullOrEmpty(href1) ? "" : "<link href='" + href1 + "' class='icerikStil anaMenu' rel='stylesheet' type='text/css' />";
        var link2 = (string.IsNullOrEmpty(href2) || link1 == "") ? "" : "<link href='" + href2 + "' class='icerikStil solMenu' rel='stylesheet' type='text/css' />";
        var link3 = (string.IsNullOrEmpty(href3) || link2 == "") ? "" : "<link href='" + href3 + "' class='icerikStil sekme' rel='stylesheet' type='text/css' />";
        var link4 = "<link href='#' id='icerikStilPozisyonu' />";

        return link1 + link2 + link3 + link4;
    }


    private static string BuyutIlkHarf(string kelime)
    {
        return string.IsNullOrEmpty(kelime) ? "" : char.ToUpper(kelime[0]) + kelime.Substring(1);
    }
}

我从视图中调用了该函数,@Html.Raw如下所示:

@Html.Raw(@headH.GetirIcerikStil(ViewBag.AnaMenuKisaAdi, ViewBag.SolMenuKisaAdi, ViewBag.SeciliTab, Url))
于 2012-08-28T08:33:38.660 回答