
input error on Row(1) Cell(3) input string was not in a correct format.<br/> input error on Row(4) Cell(3) input string was not in a correct format.<br/>
我希望br会在HTML中写一个换行符.它不是.我希望错误消息看起来像这样
input error on Row(1) Cell(3) input string was not in a correct format.input error on Row(4) Cell(3) input string was not in a correct format.
有任何想法吗?
解决方法 使用字符串[]来保存错误.这样,它们是一个格式良好且不同的错误集,而不仅仅是一个长字符串.在Controller中,初始化VIEwBag属性:
VIEwBag.Errors = new string[] { "First error","Second error" }; 在您的视图中,显示以下错误:
@foreach (string error in VIEwBag.Errors){ @HTML.Label(error) <br />} 关注点分离
您不应该在Controller中处理标记布局(即换行符或任何其他DOM元素).演示文稿应仅由VIEw查看.这就是为什么最好传递一个字符串[].
总结以上是内存溢出为你收集整理的c# – MVC3在ViewBag文本中添加换行符全部内容,希望文章能够帮你解决c# – MVC3在ViewBag文本中添加换行符所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)