How to use ScriptManager with Razor in MVC 4?

2019-08-24 02:48发布

问题:

I used ScriptManager in .aspx page to Maintain URL history in .Net i.e.

on aspx page i put this script after form tag

> <asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true"
>         EnableHistory="true">       
>     </asp:ScriptManager>

and in my .js file i put this code

Sys.Application.add_navigate(function (sender, e) {
    navigate(sender, e);
});

 Sys.Application.addHistoryPoint(objOut, null);

Now same thing i want to use in MVC 4 with Razor

I used MicrosoftAjax.js for ScriptManager and .js code is same. but i am getting issue on callback.

let me explain you with example:

suppose Actual URL is
www.websitename.com/cat/30/

anchor tag link on page is 
www.websitename.com/cat/30/?q=10

once callback perform anchor tag link becomes
www.websitename.com/?q=10

I mean after callback "cat/30/" is missing from link.

can anyone tell me what I am doing wrong.

Thanks.

Ashu

回答1:

ScriptManager is part of ASP.NET Webforms. It is not available in ASP.NET MVC. They are two completely different frameworks.

There is a port of ScriptManager to ASP.NET MVC which is available here. It might provide what you are looking for.