Looking for a similar solution effect as the updatepanel in web forms, but for MVC, below is a bit about my problem in particular. I'm sure there are many ways to do this, but ideally I want the best and most proper way.
I have looked at this question but couldn't get it to work.
Update: It can postback; MVC equivalent. I just need the position of the page maintained for the user's perspective.
I have tried the below at the bottom of my Index page but no dice.
@section Scripts
{
<script type="text/javascript">
window.scrollTo = function( x,y ) {
return true;
}
</script>
}
As well as: Controller
ViewBag.JumpTo = "equipmentAnchor";
return RedirectToAction("Index");
Index
<div id="equipmentAnchor"></div>
@section Scripts
{
<script type="text/javascript">
$(document).ready(function () {
var JumpTo = '@ViewBag.JumpTo';
if (JumpTo != "") {
$(this).scrollTop($('#' + JumpTo).position().top);
}
});
</script>
}
What is the best/easiest way to achieve this?
I've seen reports that AJAX is heavy on the server, but not overly fussed about that, preferably no CSS tricks (if there are any). JQuery is not something I am overly familiar with, but could lead to be the best solution, however not particularly well versed in it so don't know where to begin.
In the below example is a list view with a delete button that goes back to a controller to iterate through the list and delete the last entry into the list. However be it add, or in this case delete, the page jumps to the top of the index page after the postback.
How should/can I stop this posting back and reloading the page, or at the very least stop the user experiencing it?
Example Code:
Index:
<div class="List">
@{Html.RenderPartial("View", Model.List);}
</div>
Partial
@using (Html.BeginForm("RemoveExisting", "PA_4"))
{
if (Model != null)
{
foreach (var ri in Model)
{
<div class="ui-grid-c ui-responsive">
<div class="ui-block-a">
<p>One</p>
<span>
@ri.One
</span>
</div>
<div class="ui-block-b">
<p>Two</p>
<span>
@ri.Two
</span>
</div>
</div>
}
}
if (Model.Count() > 0)
{
<div>
<input type="submit" value="Remove"/>
</div>
}
}