C# 如何在ASP.NET MVC中将多个值保存到一个文本文件中
我需要将多个文本框中的多个值保存到一个文本文件中。我只能保存C# 如何在ASP.NET MVC中将多个值保存到一个文本文件中,c#,asp.net-mvc,C#,Asp.net Mvc,我需要将多个文本框中的多个值保存到一个文本文件中。我只能保存名,但不能保存姓。关于如何将姓氏和名字保存到一个文本文件中,有什么建议吗 这是我的控制器: public class SampleController : Controller { // // GET: /Sample/ [HttpPost] public ActionResult Create(Information information)
名
,但不能保存姓
。关于如何将姓氏和名字保存到一个文本文件中,有什么建议吗
这是我的控制器:
public class SampleController : Controller
{
//
// GET: /Sample/
[HttpPost]
public ActionResult Create(Information information)
{
var byteArray = Encoding.ASCII.GetBytes(information.FirstName);
var stream = new MemoryStream(byteArray);
return File(stream, "text/plain", "your_file_name.txt");
}
[HttpGet]
public ActionResult Create()
{
return View();
}
}
使用一个临时变量使用某种分隔符(空格?)存储这两个信息,然后从此临时变量中获取字节。另外,请考虑ASCII编码不是用于人名的最佳解决方案。您能在代码方面帮助我吗?我的第一条注释中有什么不清楚的地方?只需创建一个包含这两个数据项的字符串。比如
GetBytes(information.FirstName+“”+information.LastName)
,也许吧?我支持关于编码的观点。UTF-8更好。
public class SampleController : Controller
{
//
// GET: /Sample/
[HttpPost]
public ActionResult Create(Information information)
{
var byteArray = Encoding.ASCII.GetBytes(information.FirstName + ";" + information.SureName);
var stream = new MemoryStream(byteArray);
return File(stream, "text/plain", "your_file_name.txt");
}
[HttpGet]
public ActionResult Create()
{
return View();
}
}