linux 如何将一个文本文件元素创建一个数组,文本文件字符串拆分然后将每个元素输出到视图表中(示例代码)...

我目前有一个文本文件,其中包含一个paygroup和一个由管道分隔的创建日期,如下例所示

PG1 | 2019年3月21日

PG2 | 2019年3月21日

PG3 | 2019年3月21日

我试图分割字符串,以便我可以输出这样的东西,但日期分割,并放置在添加日期。

eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9ZSlVFMi5wbmcifQ==

但是,当我提取数据时,它会在一列之下。如何从列表中循环日期以显示在正确的薪资组旁边?我现在将它拆分为读入数组,然后放入列表中。我不确定是否有更好的更优化方式?

View

@model WebApplication2.Models.UploadFiles

@{

ViewBag.Title = "Paygroup Edit";

Layout = "~/Views/Shared/_Layout.cshtml";

}

Update Paygroup

@using (Html.BeginForm("Edit", "UpdateFiles", FormMethod.Post, new { enctype = "multipart/form-data" }))

{

@Html.AntiForgeryToken()

@Html.LabelFor(m => m.PayGroup, new { @class = "control-label" })

@Html.EditorFor(m => m.PayGroup, new { htmlAttributes = new { @class = "form-control", placeholder = Html.DisplayNameFor(m => m.PayGroup) } })

@Html.ValidationMessageFor(m => m.PayGroup, "", new { @class = "text-danger" })

}

PaygroupsDate added

@foreach (var pg in Model.Paygroups)

{

@pg

}

@foreach (var date in Model.DateAdded)

{

@date

}

调节器

public class UpdateFilesController : Controller

{

// GET: Default

public ActionResult Edit()

{

var fullpath = Path.Combine(Server.MapPath("~/sourcefiles"), "paygroup.txt");

List paygroupsList = new List();

List DateList = new List();

string line;

using (var sr = new StreamReader(fullpath))

{

while ((line = sr.ReadLine()) != null)

{

string[] strArray = line.Split('|');

paygroupsList.Add(strArray[0]);

DateList.Add(strArray[1]);

}

UploadFiles model = new UploadFiles()

{

Paygroups = paygroupsList,

DateAdded = DateList

};

return View(model);

}

}

模型

public class UploadFiles

{

public List Paygroups { get; set; }

public List DateAdded { get; set; }

[Required(ErrorMessage = "Please enter a paygroup.")]

[Remote("DoesPaygroupExist", "UpdateFiles", HttpMethod = "POST", ErrorMessage = "Paygroup already exists!")]

public string PayGroup { get; set; }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值