I finally managed to update PartialView with Ajax. The purpose of partial viewing is a sidebar widget that displays the contents of the registration and allows you to remove items from the registration.
An abbreviated version of PartialView is as follows:
<table id="item-entries">
@foreach (var item in Model.Items)
{
<tr>
<td>@item.Name</td>
<td>@item.Price</td>
<td>
@using (Ajax.BeginForm("RemoveItemEntry", "Registration", new AjaxOptions { UpdateTargetId = "item-entries" }))
{
<button type="submit" name="ItemId" value="@item.ItemId">×</button>
}
</td>
</tr>
}
</table>
And here is a shortened action example:
[HttpPost]
public ActionResult RemoveItemEntry(ItemViewModel data)
{
return PartialView("~/Views/Partials/ItemEntries.cshtml", model);
}
}
This works fine now, however I do not want to offer a broken experience for those who have JavaScript disabled. If you publish a form with JavaScript disabled, the action still performs correctly, but you are redirected to a URL that displays a PartialView and nothing more. I would like users who have JavaScript disabled to be redirected back to the original page from which the form was submitted.
Is this achievable?