asp.net mvc - MVC/Razor : Conditional nested html tag -
i'd have html code status ("mybool") true :
<div> <fieldset> <legend> @sometext </legend> ... other stuffs </fieldset> <div>
and 1 when it's false :
<div> <b> @sometext </b> ... other stuffs <div>
i dont whave write se same code ("other stuffs") twice tried :
<div> @if(mybool) { <fieldset> <legend> } else { <b> } @sometext if (mybool) { </legend> } else { </b> } ...other stuff if (mybool) { </fieldset> } </div>
but compilation errors.
do see how want without having somethig :
@if(mybool) { <div> <fieldset> <legend> @sometext </legend> ... other stuffs </fieldset> <div> } else { <div> <b> @sometext </b> ... other stuffs <div> }
thank you.
the next might work using @:
operator:
<div> @if (somecondition) { @:<fieldset> @:<legend> } else { @:<b> } @sometext if (somecondition) { @:</legend> } else { @:</b> } ... other stuffs @if (somecondition) { @:</fieldset> } </div>
or might seek following:
<div> @html.raw(somecondition ? "<fieldset><legend>" : "<b>") @sometext @html.raw(somecondition ? "</legend>" : "</b>") ... other stuffs @if (somecondition) { @:</fieldset> } </div>
html asp.net-mvc razor
No comments:
Post a Comment