Change URL Request Ajax PartialView

2

I need to change the page URL according to PartialView that I upload via Ajax.

@EDIT

In addition, I also need to release the direct access to PartialView via URL, but, bringing the "parent" page with me because I work with it so that it performs functions of MasterPage, that is, load in it scripts and layout. I wanted to avoid importing my scripts on every page.

Resolved by adding $ ('# rodape'). load ('/ Web / Rodape'); to render a PartialView as a footer

I have the following code in my View

 <div class="conteudo">
 <!-- Conteudo regular do site -->
 </div>
 <div id="corpoConteudo"></div>

via Ajax, I load the contents of PartialView into <div id="corpoConteudo">

My script is this

    function Open(url) {
        Carregar();
        url = '@Url.Content("~/")' + url;
        $.ajax({
            url: url,
            type: 'GET',
            success: function (response) {
                $('#corpoConteudo').html(response);
                $('#loader').remove();
            },
            error: function () {
                alert('Ocorreu um erro!');
                $('#loader').remove();
            }
        });
    }

    function Carregar() {
        $('#corpoConteudo').append('<div id="loader"></div>');
    }
    
asked by anonymous 20.08.2014 / 18:48

1 answer

2

The best way to do this is to implement Actions which only responds to Ajax. To do this, implement an attribute that only answers Ajax, something like this:

public class AjaxOnlyAttribute : ActionMethodSelectorAttribute 
{
    public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
    {
        return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest();
    }
}

Decorate your Action as follows:

[AjaxOnly]
public ActionResult Rodape()
{
   ...
} 
    
21.08.2014 / 04:51