Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#将多个字符串(中间有换行符)放入一个文本区域(MVC)_C#_String_Asp.net Mvc 3_Model View Controller_String Formatting - Fatal编程技术网

C#将多个字符串(中间有换行符)放入一个文本区域(MVC)

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

我有3个字符串,其格式如下(每一行):

“字符串1”

“字符串2”

“字符串3”


在“我的视图”中(仍绑定到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。。。我不太清楚你在问什么。