Я хочу иметь возможность редактировать / обновлять проект и показывать все вехи для этого проекта, а также иметь возможность создавать / удалять / редактировать встраиваемые файлы, чтобы он обновлял sh вехи при создании / удалении вехи. В настоящее время у меня есть, где он отображает информацию о проекте и вехи под ним ( Снимок экрана, как это выглядит ). У меня проблема в том, что я не могу переосмыслить sh частичное представление о вехе. Когда я нажимаю «удалить», он делает go путь удаления и идентификатор: После нажатия «удалить» .
I go здесь, чтобы вызвать страницу: ... / WrapperProjectMilestone / DetailEdit / 3237
В Интернете я нашел пример того, как вернуть частичное представление, и он просто использовал "publi c IActionResult Delete (", а не "publi c asyn c Task") ... вот как я пытался заставить его работать.
Спасибо за любую помощь! Вот мой код:
Контроллер:
public async Task<IActionResult> DetailEdit(int? id)
{
if (id == null)
{
return NotFound();
}
var project = await _context.Project
.Include(p => p.BuildingType)
.Include(p => p.Client)
.Include(p => p.CreatedBy)
.Include(p => p.Owner)
.Include(p => p.PrimaryContact)
.Include(p => p.Program)
.Include(p => p.ProjectStatus)
.Include(p => p.ProjectType)
.Include(p => p.Milestone)
.SingleOrDefaultAsync(m => m.ProjectId == id);
if (project == null)
{
return NotFound();
}
var client = await _context.Client.SingleOrDefaultAsync(m => m.ClientId == project.ClientId);
ViewData["BuildingTypeId"] = new SelectList(_context.BuildingType, "BuildingTypeId", "Name", project.BuildingTypeId).OrderBy(s => s.Text);
ViewData["ClientId"] = new SelectList(_context.Client, "ClientId", "Name", project.ClientId).OrderBy(s => s.Text);
ViewData["CreatedById"] = new SelectList(_context.AspNetUsers, "Id", "FullName", project.CreatedById).OrderBy(s => s.Text);
ViewData["ProjectManagerId"] = new SelectList(_context.AspNetUsers, "Id", "FullName", project.ProjectManagerId).OrderBy(s => s.Text);
ViewData["OwnerId"] = new SelectList(_context.AspNetUsers, "Id", "FullName", project.OwnerId).OrderBy(s => s.Text);
ViewData["PrimaryContactId"] = new SelectList(_context.Node, "NodeId", "Name", project.PrimaryContactId).OrderBy(s => s.Text);
ViewData["ProgramId"] = new SelectList(_context.Program, "ProgramId", "Name", project.ProgramId).OrderBy(s => s.Text);
ViewData["ProjectStatusId"] = new SelectList(_context.ProjectStatus, "ProjectStatusId", "Name", project.ProjectStatusId).OrderBy(s => s.Text);
ViewData["ProjectTypeId"] = new SelectList(_context.ProjectTypes, "ProjectTypeId", "Name", project.ProjectTypeId).OrderBy(s => s.Text);
ViewData["ProjectNameFormatId"] = new SelectList(_context.ProjectNameFormat, "ProjectNameFormatId", "ProjectNameFormat1", client.ProjectNameFormatId).OrderBy(s => s.Text);
ViewData["PaymentTypeId"] = new SelectList(_context.PaymentType, "PaymentTypeId", "PaymentType1", project.PaymentTypeId).OrderBy(s => s.Text);
return View(project);
}
[HttpPost]
public IActionResult Delete(int? id)
{
if (id == null)
{
return NotFound();
}
var milestone = _context.Milestone
.SingleOrDefault(m => m.MilestoneId == id);
if (milestone == null)
{
return NotFound();
}
else
{
_context.Milestone.Remove(milestone);
_context.SaveChanges();
}
WrapperProjectMilestone wrapperModel = new WrapperProjectMilestone();
wrapperModel.Projects = _context.Project.Where(p => p.ProjectId == id);
wrapperModel.Milestones = _context.Milestone.Where(p => p.ProjectId == id);
return PartialView("_Milestones", wrapperModel.Milestones);
}
[HttpPost]
public JsonResult CreateMilestone([FromBody]Milestone milestone)
{
//Milestone milestone = new Milestone();
if (milestone != null)
{
if (milestone.MilestoneName != null)
{
if (ModelState.IsValid)
{
_context.Add(milestone);
_context.SaveChangesAsync();
}
}
}
//var project = _context.Project.SingleOrDefault(m => m.ProjectId == milestone.ProjectId);
return Json("json");
//return PartialView("_Milestones", _context.Milestone);
}
DetailEdit .cs html
@model PM.Models.Project
@{
ViewData["Title"] = "DetailEdit";
Layout = "~/Views/Shared/_LayoutNoHeader.cshtml";
}
<form asp-action="Edit">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
...
<div id="hidesection">--Show More Project Info--</div>
...
<div class="">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<i class="icon-calendar"></i>
<h3 class="panel-title"><a data-toggle="collapse" href="#billingInfo" aria-expanded="false" aria-controls="billingInfo">Billing Info</a></h3>
</div>
<div class="panel-body collapse multi-collapse in" id="billingInfo">
<div class="row">
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="Billable" class="control-label"></label>
<select asp-for="Billable" class="form-control"><option value="False">No</option><option value="True">Yes</option></select>
<span asp-validation-for="Billable" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="BillingCode" class="control-label"></label>
<input asp-for="BillingCode" class="form-control" />
<span asp-validation-for="BillingCode" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="BillAfter" class="control-label"></label>
<input asp-for="BillAfter" class="form-control" />
<span asp-validation-for="BillAfter" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="Invoiced" class="control-label"></label>
<select asp-for="Invoiced" class="form-control"><option value="False">No</option><option value="True">Yes</option></select>
<span asp-validation-for="Invoiced" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="InvoiceDate" class="control-label"></label>
<input asp-for="InvoiceDate" class="form-control" />
<span asp-validation-for="InvoiceDate" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="InvoiceNumber" class="control-label"></label>
<input asp-for="InvoiceNumber" class="form-control" />
<span asp-validation-for="InvoiceNumber" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="Paid" class="control-label"></label>
<select asp-for="Paid" class="form-control"><option value="False">No</option><option value="True">Yes</option></select>
<span asp-validation-for="Paid" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="PaymentTypeId" class="control-label"></label>
<select asp-for="PaymentTypeId" class="form-control" asp-items="ViewBag.PaymentTypeId"><option value="">None</option></select>
<span asp-validation-for="PaymentTypeId" class="text-danger"></span>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<i class="icon-calendar"></i>
<h3 class="panel-title"><a data-toggle="collapse" href="#feeInfo" aria-expanded="false" aria-controls="feeInfo">Finance Info</a></h3>
</div>
<div class="panel-body collapse multi-collapse in" id="feeInfo">
<div class="row">
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="TotalFee" class="control-label"></label>
<input asp-for="TotalFee" class="form-control" />
<span asp-validation-for="TotalFee" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="ConsultantFee" class="control-label"></label>
<input asp-for="ConsultantFee" class="form-control" />
<span asp-validation-for="ConsultantFee" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="NetFee" class="control-label"></label>
<input asp-for="NetFee" class="form-control" />
<span asp-validation-for="NetFee" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="BudgetedCost" class="control-label"></label>
<input asp-for="BudgetedCost" class="form-control" />
<span asp-validation-for="BudgetedCost" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="BudgetedHours" class="control-label"></label>
<input asp-for="BudgetedHours" class="form-control" />
<span asp-validation-for="BudgetedHours" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="ActualEffort" class="control-label"></label>
<input asp-for="ActualEffort" class="form-control" />
<span asp-validation-for="ActualEffort" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="HourlyAmt" class="control-label"></label>
<input asp-for="HourlyAmt" class="form-control" />
<span asp-validation-for="HourlyAmt" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="HourlyNoExc" class="control-label"></label>
<input asp-for="HourlyNoExc" class="form-control" />
<span asp-validation-for="HourlyNoExc" class="text-danger"></span>
</div>
</div>
</div>
</div>
</div>
<div class="">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<i class="icon-calendar"></i>
<h3 class="panel-title"><a data-toggle="collapse" href="#scheduleInfo" aria-expanded="false" aria-controls="feeInfo">Scheduling</a></h3>
</div>
<div class="panel-body collapse multi-collapse in" id="scheduleInfo">
<div class="row">
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="StartDate" class="control-label"></label>
<input asp-for="StartDate" class="form-control" />
<span asp-validation-for="StartDate" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="DueDate" class="control-label"></label>
<input asp-for="DueDate" class="form-control" />
<span asp-validation-for="DueDate" class="text-danger"></span>
</div>
<div class="col-lg-4 col-sm-4 form-group">
<label asp-for="ActualEndDate" class="control-label"></label>
<input asp-for="ActualEndDate" class="form-control" />
<span asp-validation-for="ActualEndDate" class="text-danger"></span>
</div>
</div>
</div>
</div>
</div>
</div> <div class="">
<div class="row">
<div class="col-lg-4 col-sm-4 form-group">
<input type="submit" value="Save" class="btn btn-primary" formtarget="_parent" />
</div>
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading clearfix">
<i class="icon-calendar"></i>
<i class="fa fa-toggle-on" aria-hidden="true"></i>
<h3 class="panel-title"><a data-toggle="collapse" href="#pInfo" aria-expanded="true" aria-controls="pInfo">Milestones</a></h3>
</div>
<div class="panel-body collapse multi-collapse in" id="pInfo" role="tabpanel">
<div id="Milestones">
<partial name="_Milestones" model="Model.Milestone" />
</div>
</div>
</div>
</form>
<div class="">
<div class="row">
</div>
</div>
<div>
</div>
@section scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<style type="text/css">
body {
padding-top: 10px !important;
}
#hidesection {
background-color: #eeeeee;
height: 25px;
width: 100%;
}
#milestonetable {
font-size: 10px !important;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
$('#parentextrasection').hide();
$('#hidesection').click(function () {
if ($(this).text() == "--Hide Extra Project Info--") {
$('#parentextrasection').hide();
$(this).text('--Show More Project Info--');
} else {
$('#parentextrasection').show();
$(this).text('--Hide Extra Project Info--');
}
});
$("#ClientId").selectpicker({
liveSearch: true,
maxOptions: 1
});
});
function OpenProjectTypes() {
return parent.window.hs.htmlExpand(null, { contentId: 'proj-types', objectType: 'iframe', width: 900, height: 450, dimmingOpacity: 0.8, wrapperClassName: '', allowSizeReduction: false, src: '/ProjectTypes/Index' });
}
$("body").on("click", "#btnAdd", function () {
var milestone = {};
milestone = {};
milestone.ProjectID = $('#ProjectId').val();
milestone.MilestoneName = $("#txtMilestoneName").val();
milestone.TotalFee = $("#txtTotalFee").val();
milestone.ActualCostNonLabor = $("#txtActualCostNonLabor").val();
milestone.NetFee = $("#txtNetFee").val();
milestone.StartDate = $("#txtStartDate").val();
milestone.DueDate = $("#txtDueDate").val();
milestone.BudgetedHours = $("#txtBudgetedHours").val();
milestone.ActualEffort = $("#txtActualEffort").val();
milestone.RemainingHours = $("#txtRemainingHours").val();
milestone.BillingCode = $("#txtBillingCode").val();
milestone.NotifyAccounting = $("#txtNotifyAccounting").val();
milestone.Invoiced = $("#txtInvoiced").val();
milestone.TotalInvoiced = $("#txtTotalInvoiced").val();
if (milestone.MilestoneName != "") {
$.ajax({
type: "POST",
url: "/WrapperProjectMilestone/CreateMilestone",
data: JSON.stringify(milestone),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r + " milestone inserted.");
}, error: function (req, status, error) {
alert(error);
}
});
}
});
</script>
}
_Milestones.cs html (частичное представление)
@using PM.Models
@model IEnumerable<PM.Models.Milestone>
@{
ViewData["Title"] = "Milestones";
}
@if (Model.Count() == 0)
{
<div class="row justify-content-center text-center">
<div class="col-12 col-md-10 mt-5">
<i class="fa fa-user fa-5x mb-5"></i>
<h2>
No Milestones
</h2>
<p class="text-muted">
You do not have any milestones yet. Add a new milestone by clicking the <strong>Add Milestone</strong> button below.
</p>
<a class="btn btn-lg btn-primary d-none d-md-inline-block mt-3" href="#">Add Milestone</a>
</div>
</div>
}
else
{
<table id="milestonetable" class="table">
<thead>
<tr>
@*<th>
@Html.DisplayNameFor(model => model.ProjectId)
</th>*@
<th>
@Html.DisplayNameFor(model => model.MilestoneName)
</th>
<th>
@Html.DisplayNameFor(model => model.TotalFee)
</th>
<th>
@Html.DisplayNameFor(model => model.ActualCostNonLabor)
</th>
<th>
@Html.DisplayNameFor(model => model.NetFee)
</th>
<th>
@Html.DisplayNameFor(model => model.StartDate)
</th>
<th>
@Html.DisplayNameFor(model => model.DueDate)
</th>
<th>
@Html.DisplayNameFor(model => model.BudgetedHours)
</th>
<th>
@Html.DisplayNameFor(model => model.ActualEffort)
</th>
<th>
@Html.DisplayNameFor(model => model.RemainingHours)
</th>
<th>
@Html.DisplayNameFor(model => model.BillingCode)
</th>
<th>
@Html.DisplayNameFor(model => model.NotifyAccounting)
</th>
<th>
@Html.DisplayNameFor(model => model.Invoiced)
</th>
<th>
@Html.DisplayNameFor(model => model.TotalInvoiced)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
@*<td>
@Html.DisplayFor(modelItem => item.ProjectId)
</td>*@
<td>
@Html.DisplayFor(modelItem => item.MilestoneName)
</td>
<td>
@Html.DisplayFor(modelItem => item.TotalFee)
</td>
<td>
@Html.DisplayFor(modelItem => item.ActualCostNonLabor)
</td>
<td>
@Html.DisplayFor(modelItem => item.NetFee)
</td>
<td>
@Html.DisplayFor(modelItem => item.StartDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.DueDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.BudgetedHours)
</td>
<td>
@Html.DisplayFor(modelItem => item.ActualEffort)
</td>
<td>
@Html.DisplayFor(modelItem => item.RemainingHours)
</td>
<td>
@Html.DisplayFor(modelItem => item.BillingCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.NotifyAccounting)
</td>
<td>
@Html.DisplayFor(modelItem => item.Invoiced)
</td>
<td>
@Html.DisplayFor(modelItem => item.TotalInvoiced)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.MilestoneId">Edit</a> |
<a asp-action="Details" asp-route-id="@item.MilestoneId">Details</a> |
<form asp-action="Delete" asp-route-id="@item.MilestoneId" data-ajax="true" data-ajax-update="#Milestones">
<button type="submit" class="btn btn-sm btn-danger d-none d-md-inline-block">
Delete
</button>
</form>
</td>
</tr>
}
</tbody>
<tfoot>
<tr>
@*<td><input type="text" id="txtProjectID" /></td>*@
<td><input type="text" class="form-control" id="txtMilestoneName" /></td>
<td><input type="text" class="form-control valid" data-val="true" data-val-number="The field Total Net Fee must be a number." value="0.00" id="txtTotalFee" /></td>
<td><input type="text" class="form-control" id="txtActualCostNonLabor" /></td>
<td><input type="text" class="form-control valid" data-val="true" data-val-number="The field Net Fee must be a number." value="0.00" id="txtNetFee" /></td>
<td><input type="date" class="form-control" id="txtStartDate" name="txtStartDate" /></td>
<td><input type="date" class="form-control" id="txtDueDate" name="txtDueDate" /></td>
<td><input type="text" class="form-control" id="txtBudgetedHours" /></td>
<td><input type="text" class="form-control" id="txtActualEffort" /></td>
<td><input type="text" class="form-control" id="txtRemainingHours" /></td>
<td><input type="text" class="form-control" id="txtBillingCode" /></td>
<td><select id="txtNotifyAccounting" class="form-control"><option value="False" selected="selected">False</option><option value="True">True</option></select></td>
<td><select id="txtInvoiced" class="form-control"><option value="False" selected="selected">False</option><option value="True">True</option></select></td>
<td><input type="text" class="form-control" id="txtTotalInvoiced" /></td>
<td><input type="button" class="btn btn-primary" id="btnAdd" value="CreateMilestone" /></td>
</tr>
</tfoot>
</table>
}