パーシャルビューから親ビューへの一時データの送信方法?私はデータベースへの保存成功に関する情報が必要です。 TempDataまたはHttpContext.Itemsを例にしてください。問題はパーシャルビューから親ビューへの一時データの送信方法
これはMVCに
@model AplikacjaHelpDesk.ViewModels.ListOrdersUserViewModel
@using AplikacjaHelpDesk.Infrastructure
@{
ViewBag.Title = "List Orders Users";
Layout = "~/Views/Shared/_LayoutAdministracja.cshtml";
}
<div class="container-fluid">
<img src="~/Content/Images/Layout/Home.png" />
<a href="link">
@Html.MvcSiteMap().SiteMapPath()
</a>
<h2><span class="glyphicon glyphicon-user"></span> <strong>List Orders </strong></h2>
<br /><br />
<div id="divLoading" class="panel panel-primary text-center text-primary" style="display:none;">
<h3><strong>Please wait for post!</strong></h3>
</div>
<div id="divLoadingForm" class="panel panel-primary text-center text-primary" style="display:none;">
<h3><strong>Please wait for form</strong></h3>
</div>
@if (ViewBag.Information != null)
{
<div class="alert alert-warning"><h4><strong>@TempData["Add-Post"]</strong></h4></div>
}*@
<table class="table table-responsive table-striped" style="text-combine-upright:all;">
<tr style="text-transform: uppercase; text-combine-upright:all;">
<th>
<label>Numer Order</label>
</th>
<th>
<label>Acceptance Date</label>
</th>
<th>
<label>Date of planned completion of the order</label>
</th>
<th>
<label>Data finish</label>
</th>
<th style="width: 160px;"></th>
<th style="width: 160px;"></th>
</tr>
@foreach (var item in Model.ListOrdersUser)
{
<tr class="panel panel-primary">
<td>
<h5><strong>Nuber Orders: @Html.DisplayFor(modeItem => item.IdOrder)</strong></h5>
</td>
<td>
@Html.DisplayFor(modelItem => item.DateAccept)
</td>
<td>
@Html.DisplayFor(modelItem => item.DataPlaningFinish)
</td>
<td>
@Html.DisplayFor(modelItem => item.DataFinish)
</td>
<td>
@Ajax.ActionLink("Show Post Order", "_ListPost", new { idOrder = @item.IdOrder }, new AjaxOptions()
{
HttpMethod = "GET",
LoadingElementId = "divLoading",
UpdateTargetId = "divPosition",
InsertionMode = InsertionMode.Replace
}, new { @class = "btn btn-primary" })
</td>
<td>
@Ajax.ActionLink("Add Answer", "_AddPost", new { idZlecenia = @item.IdZlecenia }, new AjaxOptions()
{
HttpMethod = "GET",
LoadingElementId = "divLoadingForm",
UpdateTargetId = "divAddPozycje",
InsertionMode = InsertionMode.Replace
}, new { @class = "btn btn-primary" })
</td>
</tr>
...
<tr id="divAddPozycje"></tr>
}
</table>
</div>
とコントローラ
[HttpPost] [ValidateAntiForgeryToken] public PartialViewResult _AddPost(int idOrder, AddPositionViewModel viewModel) { var findOrder = db.Order.Find(idOrder); if (ModelState.IsValid) { OrderPosition position = new OrderPosition { Description = viewModel.Description }; db.OrderPosition.Add(position); //db.Entry(position).State = System.Data.Entity.EntityState.Unchanged; findOrder.OrderPositionList.Add(position); db.SaveChanges(); ViewBag.Information = position; if (ViewBag.Information != null) { TempData["Add-Post"] = string.Format("Odpowiedz użytkownika {0} została dodana!", User.Identity.Name); //HttpContext.Items["Info"] = string.Format("Odpowiedz użytkownika {0} została dodana!", User.Identity.Name); } } Thread.Sleep(2000); return PartialView(); } //Method Parent View public ActionResult ListOrder(int? IdStatusOrder) { var ListAllOrder = db.Order.ToList(); var userId = User.Identity.GetUserId(); var viewodel = new ListOrdersUserViewModel() { ListOrdersUser = ListOrders }; }; return View(viewodel); }
、ビュー内のメソッドである(親ビューに一部のビューから)差分表示の間保存の成功に関する情報を送信する方法であります部分ビュー - フォーム
@model AplikacjaHelpDesk.ViewModels.AddPositionViewModel
@{
ViewBag.Title = "Add Post";
Layout = null;
}
<link href="~/Content/font-awesome.min.css" rel="stylesheet" />
<script src="~/Scripts/tinymce/tinymce.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/jquery-2.2.3.min.js"></script>
<div class="container-fluid" >
@using (Ajax.BeginForm(new AjaxOptions()
{
UpdateTargetId = "divformResult",
HttpMethod = "Post"
}))
{
@Html.AntiForgeryToken()
@Html.Hidden("IdOrder")
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-1" })
<div class="col-md-10" >
@Html.TextAreaFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10 ">
<input type="submit" value="Send" class="btn btn-danger" id="formularz"/>
</div>
</div>
</div>
}
</div>
@*@if (TempData["Add-Post"] != null)
{
<div class="alert alert-warning">
<h4><strong>@TempData["Add-Post"];</strong></h4>
</div>
}*@
<script type="text/javascript">
tinymce.init({
selector: "textarea",
language: "pl",
theme: "modern",
fontsize_formats: "8pt 10pt 12pt 14pt 18pt 24pt 36pt 48pt 72pt",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste",
"textcolor",
"colorpicker",
],
theme_advanced_fonts: "Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;AkrutiKndPadmini=Akpdmi-n",
extended_valid_elements: 'i[class]',
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | forecolor backcolor | fontsizeselect"
});
</script>
あなたはAjax.ActionLink' @ '使用しています。親ビューは、部分ビューが呼び出されるずっと前にレンダリングされます。 – aaron
書き込み後、メッセージは非同期で表示され、ビューを再読み込みする必要はありません。 –
正確に、あなたは 'TempData'にアクセスできません。 – aaron