C#将多个字符串(中间有换行符)放入一个文本区域(MVC)
我有3个字符串,其格式如下(每一行): “字符串1” “字符串2” “字符串3”C#将多个字符串(中间有换行符)放入一个文本区域(MVC),c#,string,asp.net-mvc-3,model-view-controller,string-formatting,C#,String,Asp.net Mvc 3,Model View Controller,String Formatting,我有3个字符串,其格式如下(每一行): “字符串1” “字符串2” “字符串3” 在“我的视图”中(仍绑定到viewmodel属性时)将此格式重新创建/传输到TextArea for的最佳方法是什么?将字符串保存在属于viewmodel的IList中。您可以使用视图模型: public class MyViewModel { public string Text { get; set; } } 将传递给视图的: public ActionResult Index() { var
在“我的视图”中(仍绑定到viewmodel属性时)将此格式重新创建/传输到TextArea for的最佳方法是什么?将字符串保存在属于viewmodel的IList中。您可以使用视图模型:
public class MyViewModel
{
public string Text { get; set; }
}
将传递给视图的:
public ActionResult Index()
{
var strings = new[] { "String 1", "String 2", "String 3" };
var model = new MyViewModel
{
Text = string.Join(Environment.NewLine, strings)
};
return View(model);
}
对于渲染:
@model MyViewModel
...
@Html.TextAreaFor(x => x.Text)
css。。。我不太清楚你在问什么。