asp.net mvc 3 - Label with HTML content -


how may create strongly-typed label html content inside in mvc3?

<label for="nnn"><input type="checkbox" id="nnn" />herp</label> 

i have checked code in w3c validator , seems valid, there way it?

thanks.

you use custom html helper tagbuilder.

something (untested);

public static mvchtmlstring labelcheckboxfor<tmodel>(    htmlhelper<tmodel> htmlhelper,     expression<func<tmodel,bool>> expression,    string text) {    var labeltag = new tagbuilder("label");    labeltag.mergeattribute("for", "nnn");     labeltag.innerhtml = htmlhelper.checkboxfor(expression) + text;    return labeltag.tostring(tagrendermode.selfclosing); } 

might not 100% idea. i'm not sure how pull "for" value out of model. might need fromlambdaexpression, or parameter.

and use this:

@html.labelcheckboxfor(model => model.somefield, "herp") 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -