Я создаю решение Asp.Net Core 2.1 EF MVC.
Вместо того, чтобы писать отдельные строки для каждой кнопки CRUD (Редактировать, Создать, Удалить) в каждом из моих представлений Индекса, я пытаюсь динамически генерировать кнопки из частичного представления следующим образом.
Модели / AdmSchool
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace FACEZ.Models
{
public partial class AdmSchool
{
[Display(Name = "Id")]
public int AdmSchoolId { get; set; }
[Required]
[MaxLength(10)]
[Display(Name = "Code")]
public string AdmSchoolCode { get; set; }
[Required]
[MaxLength(100)]
[Display(Name = "School Name")]
public string AdmSchoolDescr { get; set; }
[MaxLength(100)]
[Display(Name = "Generic Email Principal")]
public string EmailPrincipal { get; set; }
[MaxLength(100)]
[Display(Name = "Generic Email Accounts")]
public string EmailAccounts { get; set; }
[MaxLength(100)]
[Display(Name = "Generic Email Registrar")]
public string EmailRegistrar { get; set; }
[Display(Name = "Obsolete")]
public bool Obsolete { get; set; }
}
}
Views / Shared / _IndividualButtonPartial
@model FACEZ.Models.IndividualButtonPartial
<a type="button" class="btn btn-sm @Model.ButtonType"
href="@Url.Action(Model.Action) @Model.ActionParameters">
<span class="glyphicon glyphicon-@Model.Glyph"></span>
<span class="sr-only">@Model.Text</span>
</a>
Views / Shared / _TableButtonPartial
@model FACEZ.Models.IndividualButtonPartial
<td style="width: 150px;">
<div class="btn-group" role="group">
@await Html.PartialAsync("_IndividualButtonPartial",
new IndividualButtonPartial {
Action="Edit",
ButtonType="btn-primary",
Glyph = "pencil",
Text = "Edit",
Id=Model.Id
})
@await Html.PartialAsync("_IndividualButtonPartial",
new IndividualButtonPartial {
Action="Details",
ButtonType="btn-success",
Glyph = "list",
Text = "Details",
Id=Model.Id
})
@await Html.PartialAsync("_IndividualButtonPartial",
new IndividualButtonPartial {
Action="Delete",
ButtonType="btn-danger",
Glyph = "trash",
Text = "Delete",
Id=Model.Id
})
</div>
</td>
Области / Впуск / Views / AdmSchools / Index.cshtml
@using Microsoft.EntityFrameworkCore.SqlServer.Query.ExpressionTranslators.Internal
@model IEnumerable<FACEZ.Models.AdmSchool>
@{
ViewData["Title"] = "Index";
}
<h2>Index</h2>
<p>
<a asp-action="Create">Create New</a>
</p>
<div class="form-border">
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.AdmSchoolCode)
</th>
<th>
@Html.DisplayNameFor(model => model.AdmSchoolDescr)
</th>
<th>
@Html.DisplayNameFor(model => model.EmailPrincipal)
</th>
<th>
@Html.DisplayNameFor(model => model.EmailAccounts)
</th>
<th>
@Html.DisplayNameFor(model => model.EmailRegistrar)
</th>
<th>
@Html.DisplayNameFor(model => model.Obsolete)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.AdmSchoolCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.AdmSchoolDescr)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailPrincipal)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailAccounts)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailRegistrar)
</td>
<td>
@Html.DisplayFor(modelItem => item.Obsolete)
</td>
<td>
@await Html.PartialAsync("_TableButtonPartial", new IndividualButtonPartial {Id=item.AdmSchoolId})
@* I am trying to replace the following code with the line above
<a asp-action="Edit" asp-route-id="@item.AdmSchoolId">Edit</a> |
<a asp-action="Details" asp-route-id="@item.AdmSchoolId">Details</a> |
<a asp-action="Delete" asp-route-id="@item.AdmSchoolId">Delete</a>
*@
</td>
</tr>
}
</tbody>
</table>
Когда я запускаю приложение, я вижу информацию о школе в индексном представлении.
Тем не менее, создаваемая ссылка действия получает в ней пробел откуда-то?
как https://localhost:44399/Adm/AdmSchools/Edit / 1 вместо
как https://localhost:44399/Adm/AdmSchools/Edit/1
Как я могу удалить пробел после имени действия.