2017-01-16 98 views
0

我在我的cshtml视图中有一个文本框(以及许多其他文本框),用户可以在其中输入一些随机文本(这可以让我多行),并保存它在数据库中。数据保存成功后,用户可以使用“查看统计”按钮查看保存的数据。点击此按钮后,所有保存的数据将以相应标签的只读模式加载。这里的问题是,用户输入的多行文本在标签中单行显示。但是,当用户尝试编辑记录(数据在文本框中消失时),数据显示为多行。如何在视图模式下实现相同的功能,我希望在标签中显示多行文本。使用jquery在CSHTML中的标签中显示多行文本

下面是我的文本框:

@using (Html.BeginInnerPanel(true, new { style = "width:100%;", id =  "pnlRemarks" }, "", false)) 
{ 
    using (Html.BeginInnerPanelBody()) 
    { 
    using (Html.BeginFieldWrap("Remarks", "", new { style = "width:100%" })) 
    { 
     @Html.TextArea("txtRemarks", "", new { style = "width:99%;height:80px; text-transform: uppercase;" }); 
    } 
    } 
} 

下面是我的标签:

@using (Html.BeginInnerPanel(true, new { style = "width:100%; display:none;", id = "pnlRemarksV" }, "", false)) 
{ 
    using (Html.BeginInnerPanelBody()) 
    { 
     using (Html.BeginFieldWrap("Remarks", "", new { style = "width:100%" })) 
    { 
     <label id="lblViewRemarks" style = "font-weight:bold"></label> 
    } 
    } 
} 

我隐藏和显示基于编辑或视图模式面板。你能帮我把标签中的文字显示为多行。

回答

0

而不是使用标签您可以使用textarea的隐藏选项,以便对你有用的只读功能

溢出:隐藏;或溢出:可见;

这样:

<textarea id="txt" type="text" style="position:absolute; top:200px; left:170px; overflow:hidden;"></textarea> 

这将是更容易,如果你使用的CSS尽管阅读你的代码。

我不确定你要做什么然后,宽度:220px;让我的文字突破。这也工作,我相信它更好地匹配我认为你想要做的事情:

#lbl{   
    max-width:220px; 
    height:auto; 
}