You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C# Razor HtmlHelper Extension for Conditional Wrapping Element Tag
Usage
Conditionally render wrapping tag
Razor
@usingUI.Extensions
@{varsomeCondition=true;}
@using (Html.Wrap("div", someCondition)){<span>This span is wrapped with a `<div>` if `someCondition` is `true`.</span>}
Output
<div><span>This span is wrapped with a `<div>` if `someCondition` is `true`.</span></div>
Conditionally set wrapping element tag
Razor
@usingUI.Extensions
@{varsomeCondition=true;vartag=someCondition?"a":"span";varattributes=someCondition?new{ href ="#"}:new{};}
@using (Html.Wrap("div", attributes, someCondition)){<span>This span is wrapped with a `<a href="#">` if `someCondition` is `true`.</span>
}
Output
<ahref="#"><span>This span is wrapped with a `<a href="#">` if `someCondition` is `true`.</span></a>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Is there any way to get the content which is inside the { } from within the HtmlWrap methods?