html标签从.net framework转移到.net standard(.net core 2.2)时遇到的坑及填坑
在原来的.net framework mvc中html的标签可以使用下面的方法
1 <select class="form-control" id="categoryinfoid" name="categoryinfoid"> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 select>
此时html标签里面属性与值的对应要求不是很高,但是在.net core 2.2中,html标签里面属性与值的必须要对应要求,上面得这种情况会报错
The tag helper 'option' must not have C# in the element's attribute declaration area.
标记帮助器"选项"在元素的属性声明区域中不得包含 C# 语句。
编辑器会认为,@(“...”)不是一个属性。
解决办法很奇特,看代码:
1 <select class="form-control" id="categoryinfoid" name="categoryinfoid"> 2 3 "22" @(categoryinfoid==22 ? "selected=selected" : "" )>内双!option> 4 "23" @(categoryinfoid==23 ? "selected=selected" : "" )>内三!option> 5 "24" @(categoryinfoid==24 ? "selected=selected" : "" )>内四!option> 6 "32" @(categoryinfoid==32 ? "selected=selected" : "" )>海双!option> 7 "33" @(categoryinfoid==33 ? "selected=selected" : "" )>海三!option> 8 "34" @(categoryinfoid==34 ? "selected=selected" : "" )>海四!option> 9 "42" @(categoryinfoid==42 ? "selected=selected" : "" )>阳双!option> 10 "43" @(categoryinfoid==43 ? "selected=selected" : "" )>阳三!option> 11 "44" @(categoryinfoid==44 ? "selected=selected" : "" )>阳四!option> 12 "52" @(categoryinfoid==52 ? "selected=selected" : "" )>套双!option> 13 "53" @(categoryinfoid==53 ? "selected=selected" : "" )>套三!option> 14 "54" @(categoryinfoid==54 ? "selected=selected" : "" )>套四!option> 15 select>
每个要使用@(“...”)的标签前面加一个“!”号就OK了,不明觉厉