1

I am using MVC4 Ajax.ActionLink for binding or updating Partial View

 @Ajax.ActionLink("Link","Action","Controller" , new {id = @Id}, new AjaxOptions { HttpMethod="Post",UpdateTargetId="dvUpdateId", OnSuccess = "scsFunctions"})

Now issue is if I try to open link by right clicking open link in New Tab or New Windows than I have following two Issues.

(1)In New Tab or New Window it is only return Partial View. So other part of Page is disappears.

(2)It Will Never call Onsuccess function and like others functions. In above code OnSuccess we define to call "scsFunctions" which will never call . So the Scripts which we have written inside function will never execute.

Help me with proper solutions....

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Dilip Langhanoja
  • 4,455
  • 4
  • 28
  • 37

1 Answers1

3

I have solved this problem. First check if is an AjaxRequest or a ChildAction. If yes return PartialView, if no return a redirectResult

public ActionResult Index(int param1, bool param2)
        {

            if (HttpContext.Request.IsAjaxRequest() || ControllerContext.IsChildAction)
            {
                return PartialView("Controls/_SingolaGallery", param1);
            }
            return new RedirectResult("http://www.myredirectUrl.com");//you can redirect in this another way--> new RedirectResult(Url.Action("ActinNAme","ControllerName")); 

          }
faby
  • 7,394
  • 3
  • 27
  • 44
  • as you provide solutions like on ajax request or childaction return only partialview , it is obvious I do like that but issue with to stop opening ajax actionlink in tab or window . Try it you will get only partialview in new tab or windows. – Dilip Langhanoja Jun 09 '14 at 08:03
  • @Dilip0165 no you should have a new instance of myredirecturl.com in the new tab... not the partial view – faby Jun 09 '14 at 08:07