English 中文(简体)
html
原标题:html helpers text input and line break
public string BannerText {get;set;}

public void SetBanner()
{
  BannerText = "This is line 1. 
This is line 2."
}

我在百页上就这样说:

<div>
  <h1><%: Model.BannerText %></h1>
</div>

然而,案文仍然只是一行。 我尝试了<代码><br />和<br>,但似乎没有工作。 我确信,它必须简单一些,但需要SO帮助:

EDIT:Kirk Woll and Mike suggestion worked! use: <h1><%= Model.BannerText %></h1>

最佳回答

What is "<%:"? I haven t seen that before. Have you tried "<%="? That will use an HTMLTextWriter to pass the string to render. Then just use HTML (<br />) in your string.

问题回答

First, will absolutely not work. This is HTML. You do need to use <br /> (or wrap them in <div>, etc.). However, the purpose of <%: (as opposed to <%=) is to HTML-encode your string. So presumably your line breaks (<br />) are being encoded. You should try <%= instead and see if that fixes your issue.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签