Note that there are some explanatory texts on larger screens.

plurals
  1. POPartial View not refreshing
    primarykey
    data
    text
    <p>I have a partial view on a cshtml page as follows :-</p> <pre><code>@model MvcCommons.ViewModels.CompositeViewModel @{ ViewBag.Title = "Edit"; } @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Article&lt;/legend&gt; @Html.HiddenFor(model =&gt; model.ArticleViewModel.Article.ArticleID) &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ArticleViewModel.Article.CategoryID, "Category") &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.DropDownListFor(model =&gt; model.ArticleViewModel.Article.CategoryID, (SelectList)ViewBag.CategoryID) @Html.ValidationMessageFor(model =&gt; model.ArticleViewModel.Article.CategoryID) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ArticleViewModel.Article.ArticleTitle) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.ArticleViewModel.Article.ArticleTitle) @Html.ValidationMessageFor(model =&gt; model.ArticleViewModel.Article.ArticleTitle) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ArticleViewModel.Article.ArticleDate) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.ArticleViewModel.Article.ArticleDate) @Html.ValidationMessageFor(model =&gt; model.ArticleViewModel.Article.ArticleDate) &lt;/div&gt; @Html.HiddenFor(model =&gt; model.PageViewModel.Page.PageTitle, new { id = "PageTitle" }) @Html.HiddenFor(model =&gt; model.PageViewModel.Page.PageAction, new { id = "PageAction" }) @Html.HiddenFor(model =&gt; model.ArticleViewModel.Article.ArticleID, new { id = "ArticleID" }) &lt;div class="ImageGallery"&gt; @Html.Partial("~/Views/Shared/ImageGallery.cshtml", Model) &lt;/div&gt; &lt;/fieldset&gt; } &lt;div&gt; @Html.ActionLink("Back to List", "Index") </code></pre> <p></p> <p>The ImageGallery.cshtml Partial View is as follows :-</p> <pre><code>@model MvcCommons.ViewModels.CompositeViewModel @{ ViewBag.Title = "Modal image uploader"; } &lt;script type="text/javascript"&gt; var pageTitle = $('#PageTitle').val(); var pageAction = $('#PageAction').val(); var id = $('#ArticleID').val(); $(document).ready(function () { $('.modal_block').click(function (e) { $('#tn_select').empty(); $('.modal_part').hide(); }); $('#modal_link').click(function (e) { $('.modal_part').show(); var context = $('#tn_select').load('/Upload/UploadImage?Page=' + pageTitle + '&amp;Action=' + pageAction + '&amp;id=' + id, function () { initSelect(context); }); e.preventDefault(); return false; }); $('#delete_images').click(function (e) { var sList = ""; $('input[type=checkbox]').each(function () { var sThisVal = (this.checked ? this.value : ""); sList += (sList == "" ? sThisVal : "," + sThisVal); }); $.ajax({ url: "/Upload/DeleteImages?IDs=" + sList + '&amp;Page=' + pageTitle + '&amp;Action=' + pageAction + '&amp;id=' + id, data: sList, cache: false, type: "POST", dataType: "json" }); reloadGallery(); return false; }); function reloadGallery() { $.ajax({ type: "GET", url: '/Upload/Index/', data: "{}", cache: false, dataType: "html", success: function (data) { $().html(data); } }) } }); &lt;/script&gt; &lt;div class="modal_block modal_part"&gt;&lt;/div&gt; &lt;div class="modal_dialog modal_part" id="tn_select"&gt;&lt;/div&gt; &lt;h2&gt;List of images&lt;/h2&gt; &lt;p&gt; This page contains the list of all uploaded images. &lt;/p&gt; @if (Model.ImageViewModel.Images.Count &gt; 0) { &lt;div class="imageContainer"&gt; &lt;div class="div-table"&gt; &lt;div class="div-table-row-title"&gt; &lt;div class="div-table-col"&gt;Image&lt;/div&gt; &lt;div class="div-table-col"&gt;Image Name&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; } &lt;/div&gt; &lt;div class="DeleteImages"&gt; &lt;a href="#" id="delete_images"&gt;Delete Selected Images.&lt;/a&gt; &lt;/div&gt; </code></pre> <p></p> <pre><code>} else { &lt;div class="imageCenter"&gt; No images have been uploaded so far. &lt;/div&gt; } &lt;p&gt; &lt;a href="#" id="modal_link"&gt;Click here to open modal dialog.&lt;/a&gt; &lt;/p&gt; &lt;div class="clear"&gt;&lt;/div&gt; </code></pre> <p>Here is the code in the Controller to delete the images:-</p> <pre><code> [HttpPost] public ActionResult DeleteImages(string IDs) { _Page = Request.QueryString["Page"]; _Action = Request.QueryString["Action"]; _ItemID = Convert.ToInt32(Request.QueryString["id"]); Generics.PageIDS currentPage = (Generics.PageIDS)Enum.Parse(typeof(Generics.PageIDS), _Page); _PageID = Convert.ToInt32(currentPage); string[] sepImageIds = IDs.Split(','); foreach (string strImageId in sepImageIds) { imageViewModel.DeleteFromXML(strImageId); } return RedirectToAction(_Action, _Page, new { id = _ItemID }); } </code></pre> <p>Everything works fine in this Partial View, except for when I delete an image, the deletion is done correctly, however when the code is passed back to the View, the Partial View is not refreshed.</p> <p>Is there something I am missing?</p> <p>Thanks for your help and time!</p> <p>------------------UPDATE--------------------------------------------- This is the Edit Controller Action after the Delete has finished :-</p> <pre><code> public ActionResult Edit(int id = 0) { articleViewModel.Article = unitOfWork.ArticleRepository.GetByID(id); pageViewModel.Page.PageTitle = "Article"; pageViewModel.Page.PageAction = "Edit"; if (articleViewModel.Article == null) { return HttpNotFound(); } PopulateDropDownList(articleViewModel.Article.CategoryID); viewModel.ArticleViewModel = articleViewModel; int ImageCount = 0; imageViewModel.Images = imageViewModel.PopulateFromXML(pageViewModel.GetPageID(_PageName), id, out ImageCount).ToList(); viewModel.ImageViewModel = imageViewModel; viewModel.PageViewModel = pageViewModel; return View(viewModel); //return Json(viewModel, JsonRequestBehavior.AllowGet); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload