Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hello,

I am working on html.beginform and ajax.beginform. lot of article and blog saying that ajax.beginform() will not redirect another view(page).

But for me it is redirecting. i have referred all scripts and configured in web.config too. all scripts are existing under scripts folder in solution file.

Note : i have tested using fiddler to check loading script or not. it is loading.

layout.cshtml

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript"></script>

web.config

<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

my controller

public class HomeController : Controller
{

[HttpGet]
public ActionResult TestAjaxView()
{
ViewBag.Message = "This is a AJAX form";
return View();
}
[HttpPost]
[ActionName("TestAjaxView")]
public ActionResult TestAjaxRedirect()
{
return RedirectToAction("About", "Home", null);
}
public ActionResult About()
{
ViewBag.Message = "This is a about form";
return View();
}
}

my view : TestAjaxView.cshtml

@{
ViewBag.Title = "TestAjaxView";
}

<h2>TestAjaxView</h2>


@using (Ajax.BeginForm("TestAjaxView", "Home", new AjaxOptions {UpdateTargetId = "result" }))
{
<div id="result">
@Html.Label("This is Ajax Form")
<input type="submit" value="Redirect" class="btn btn-default" />
</div>
}

finally it is redirecting about.cshtml. how? what i did mistake?

help needed.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900