asp.net mvc - MVC Parameterized Element -
i have partial view want display different type of html element based on property of model. solution i've come is:
@if (model.element == "span") { <span> stuff </span> } else if (model.element == "p") { <p> stuff </p> } else { <div> somestuff </div> }
this not extensible. i'd write like:
<@model.element> stuff </@model.element>
but doesn't seem allowed. there way this.
(i appreciate goes against grain of mvc model , therefore controller specifying html. actually, element type comes parent view, think okay.)
many in advance.
@html.raw("<" + model.element + ">") stuff @html.raw("</" + model.element + ">")
is simple possible. though use tagbuilder
:
@{ tagbuilder tb = new tagbuilder(model.element); tb.innerhtml = "some stuff"; @html.raw(tb.tostring()) }
Comments
Post a Comment