Stop Page Movement in PostBack On Razor Partial HtmlBeginForm

You are looking for a similar solution effect like updatepanel in web forms, but for MVC below is a little about my problem in particular. I am sure that there are many ways to do this, but ideally I want the best and most correct way.

I reviewed this question , but could not get it to work.

Update: It could be a postback; MVC equivalent. I just need the position of the page maintained for the user's perspective.

I tried the following on my index page, but did not play dice.

@section Scripts
{
<script type="text/javascript">
    window.scrollTo = function( x,y ) {
     return true;
    }
</script>
}

Also like: 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?

, AJAX , , CSS ( ). JQuery - , , , , , .

, . , , .

/ , , , , ?

:

<div class="List">
                    @{Html.RenderPartial("View", Model.List);}
                </div>

@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>
    }
}
+4
2

.

GitHub @section Scripts

:

@section Scripts
{
<script type="text/javascript" src="~/Scripts/maintainscroll.jquery.min.js">

</script>
}
+1

ajax... jquery.unobtrusive-ajax.js , woork jquery ofcourse. ( nuget).

, Html.BeginForm, id ( div), html-. , , ajax HTML targetId ( dom). : . entier div.

:

:

    @using (Ajax.BeginForm("RemoveExisting", new AjaxOptions() {
        HttpMethod = "POST",
        OnBegin = "OptionalJSFunction",
        OnFailure = "OptionalJSFunction",
        OnSuccess = "OptionalJSFunction",
        UpdateTargetId = "targetId"
    }))
    { 
         //Your form goes in here..
    } 

<div id="targetId">
</div>

:

    [HttpPost]
    public ActionResult RemoveExisting(YourModel model)
    {
       //your code in here
       return PartialView("YourView",model);
    }
+1

All Articles