开发者

Asp.net MVC 3 Razor code problem in a if statement

开发者 https://www.devze.com 2023-02-04 06:01 出处:网络
I have the following asp.net mvc 3 razor code, where \"item\" is my model, <a @if (item.Selected) { class=\"youarehere\" } href=\"@item开发者_运维知识库.Href\" title=\"@item.Title\">@item.Descr

I have the following asp.net mvc 3 razor code, where "item" is my model,

<a @if (item.Selected) { class="youarehere" } href="@item开发者_运维知识库.Href" title="@item.Title">@item.Description</a>  

This code throws up the following error,

CS1513: } expected

which is pointing to

class="youarehere"

portion of the code, but I could not figure out why. Could someone help point out how to fix it please? Thank you.


Try This:

<a @(item.Selected ? "class='youarehere'" : "") href="@item.Href" ... 


Try this:

<a @if (item.Selected) { @:class="youarehere" } 
 href="@item.Href" 
 title="@item.Title">
 @item.Description
</a> 
0

精彩评论

暂无评论...
验证码 换一张
取 消