【问题标题】:how to find point in line and then after add a content in new line如何在行中查找点,然后在新行中添加内容
【发布时间】:2020-09-21 06:08:32
【问题描述】:

现在我的内容是一行,但我想新内容是点之后的新行(。)

.cs

        [HttpGet]
        public async Task<ActionResult> Career()
        {
            HttpClient client = new HttpClient();
            HttpResponseMessage responseMessage = client.GetAsync("https://localhost:0000/Home/DisplayVacancyData").Result;

            if (responseMessage.IsSuccessStatusCode)
            {
                //data = await responseMessage.Content.ReadAsAsync();
                //List<Vacancy> products = await responseMessage.Content.ReadAsAsync<List<Vacancy>>();
                string result = await responseMessage.Content.ReadAsStringAsync();
                List<Vacancy> vaca = JsonConvert.DeserializeObject<List<Vacancy>>(result);
                ViewBag.message = vaca + "<br />";
                return View("Career",vaca);
                 
            }
            return View();
        }

.cshtml

<table class="table table-striped border">
    <thead>
        <tr>
            <th>Vacancy Title</th>
            <th>Vacancy Position</th>
            <th>Vacancy Experience</th>
            <th>Vacancy Jobdescription</th>
            <th>Vacancy RequiredSkil</th>
            <th>Action</th>
        </tr>
    </thead>

    <tbody>
        @foreach (var carr in Model)
        {
            //string newline = "\n";

            <tr>
                <td>@carr.vacancytitle</td>
                <td>@carr.vacancyposition</td>
                <td>@carr.vacancyexperience</td>

                @*if()*@

                <td>@carr.vacancyjobdescription@*<text> & nbsp;</ text >*@</td>
                <td>@carr.vacancyrequiredskill</td>
                <td>
                    @Html.ActionLink("Apply for Job", "ApplyForJob")
                </td>
            </tr>
        }
    </tbody>
</table>

表示在单独的行中添加新内容

逻辑是首先在行中找到点(。)然后添加新行

string newline = "\n";
if(carr.vacancyjobdescription)
{   
   //issue is here how to find out point in line
   and then add a <text>newline</text>
   
}

我正在尝试的 - 主要问题是如何找到重点

               <td>
                    @if (carr.vacancyjobdescription != null)
                    {
                        @carr.vacancyjobdescription
                        <text>&nbsp;</text>
                    }
                </td>

【问题讨论】:

  • 通过在控制器操作方法中用 替换您的点来操作您的 vacancyrequiredskill 属性值,然后在视图中使用 @Html.Raw() 函数
  • @MayurAsodariya 我没有静态内容数据来自数据库ViewBag.message = vaca + "&lt;br /&gt;"; vaca 不是静态内容,请参阅我添加了有问题的控制器代码

标签: c# html asp.net-mvc


【解决方案1】:
    <td>

        @{
            string skillHtml = @carr.vacancyrequiredskill;
            skillHtml = skillHtml.Replace(".", "</br>");
        }
        @*Here we gonna display the html*@
        @Html.Raw(skillHtml)
    </td>

【讨论】:

    【解决方案2】:
    @{string data = "Hello. This is Test. Yo";
    data= data.Replace(".", "</br>");}
    
    
    @*Then to display your value  use...*@
    @Html.Raw(data)
    

    【讨论】:

    • 问题已解决我想以直线显示内容(意味着第一行内容以直线显示)我做错了我在表格中的全部内容i.stack.imgur.com/MPBvf.png
    • 如果建议的解决方案不相关,您可以提供两个单独的答案。但是,对于相关的解决方案,请在相同的答案中提供它们,而不是编辑您的原始答案。
    • @MichaelSchnerring 我会注意的。
    猜你喜欢
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    相关资源
    最近更新 更多